HttpClient setting boundary with content-type

后端 未结 3 840
野的像风
野的像风 2021-01-13 02:09

I am using javascript to communicate with a third party service. As part of their authentication process they need the \"multipart/form\" body of the post message including

3条回答
  •  灰色年华
    2021-01-13 03:05

    We solved this by manually clearing and re-adding the content type without validation it seems that the MediaTypeHeaderValue() class doesn't like the boundary tags.

    instead of using :

    content.Headers.ContentType = new MediaTypeHeaderValue("multipart/form-data; boundary=----FLICKR_MIME_20140415120129--");
    

    we did the following:

    content.Headers.Remove("Content-Type");
    content.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=----FLICKR_MIME_20140415120129--");
    

    Once we made this change it all worked correctly.

    (Note that this is on WinRT if that makes any difference)

提交回复
热议问题