Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# webclient post file

private async Task<System.IO.Stream> Upload(string actionUrl, string paramString, Stream paramFileStream, byte [] paramFileBytes)
{
    HttpContent stringContent = new StringContent(paramString);
    HttpContent fileStreamContent = new StreamContent(paramFileStream);
    HttpContent bytesContent = new ByteArrayContent(paramFileBytes);
    using (var client = new HttpClient())
    using (var formData = new MultipartFormDataContent())
    {
        formData.Add(stringContent, "param1", "param1");
        formData.Add(fileStreamContent, "file1", "file1");
        formData.Add(bytesContent, "file2", "file2");
        var response = await client.PostAsync(actionUrl, formData);
        if (!response.IsSuccessStatusCode)
        {
            return null;
        }
        return await response.Content.ReadAsStreamAsync();
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: bash create temporary folder 
Csharp :: c# get all namespaces in assembly 
Csharp :: c# remove char from string 
Csharp :: unity text color 
Csharp :: convert list string to list long c# 
Csharp :: wpf toolbar disable overflow 
Csharp :: C# return and set multiple values from method 
Csharp :: minimize maximize restore wpf buttons 
Csharp :: c# datetime for filename 
Csharp :: list to ienumerable c# 
Csharp :: c# file watcher 
Csharp :: c# kill one excel process 
Csharp :: where in used in linq c# 
Csharp :: append multi lines to file linux 
Csharp :: how to find the tag of an objecdt in unity 
Csharp :: c# wpf image source from resource programmatically 
Csharp :: Show private fields in Unity Inspector 
Csharp :: cast char[] to string c# 
Csharp :: unity onclick object 
Csharp :: c# code to read txt file line by line and split 
Csharp :: All Possible SubString 
Csharp :: dapper sql builder where 
Csharp :: how to make a 3d object do something when clicked on 
Csharp :: linked list reverse 
Csharp :: c# combobox with text and value 
Csharp :: C# Switch and case 
Csharp :: remove item from list in for loop c# 
Csharp :: unity 2d enemy patrol script 
Csharp :: longest substring without repeating characters 
Csharp :: winforms input box 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =