Skip to content

Instantly share code, notes, and snippets.

@dbeattie71
Created March 23, 2014 19:11
Show Gist options
  • Save dbeattie71/9728149 to your computer and use it in GitHub Desktop.
Save dbeattie71/9728149 to your computer and use it in GitHub Desktop.
How to get double quotes around 'name' and 'filename' on Xamarin Monotouch iOS with the HttpClient.
else if (restRequest.ContentType == ContentTypes.MultipartFormData)
{
var multipartPartFormDataContent = new MultipartFormDataContent();
var contentJson = new StringContent(restRequest.GetRequestBody());
multipartPartFormDataContent.Add(contentJson);
httpRequestMessage.Content = contentJson;
if (restRequest.Files.Any())
foreach (var fileParameter in restRequest.Files)
{
var streamContent =
new StreamContent(new MemoryStream(fileParameter.Data, 0, fileParameter.Data.Length));
streamContent.Headers.ContentDisposition =
ContentDispositionHeaderValue.Parse("form-data");
streamContent.Headers.ContentDisposition.Parameters.Add(new NameValueHeaderValue(
"name",
string.Format("\"{0}\"",
fileParameter
.Name)));
streamContent.Headers.ContentDisposition.Parameters.Add(
new NameValueHeaderValue("filename",
string.Format("\"{0}\"", fileParameter.FileName)));
multipartPartFormDataContent.Add(streamContent);
}
httpRequestMessage.Content = multipartPartFormDataContent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment