HttpContent double border quotes

I have this sample code that was sent as an answer to another question ( Send file via HTTP POST with C # ). It works great except for one question. It surrounds the border in the HTTP header with double quotes:

multi-part / form data; border = "04982073-787d-414b-a0d2-8e8a1137e145"

This delays the web service I'm trying to call. Browsers do not have these double quotes. I need to somehow tell .NET to leave them.

private 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 = client.PostAsync(actionUrl, formData).Result; if (!response.IsSuccessStatusCode) { return null; } return response.Content.ReadAsStreamAsync().Result; } } 
+5
source share
1 answer

You can remove quotes from the border using the following code:

 var boundary = formData.Headers.ContentType.Parameters.First(o => o.Name == "boundary"); boundary.Value = boundary.Value.Replace("\"", String.Empty); 
+1
source

All Articles