{"id":6214,"date":"2014-04-13T23:29:59","date_gmt":"2014-04-13T23:29:59","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/13\/httpclient-setting-boundary-with-content-type-collection-of-common-programming-errors\/"},"modified":"2014-04-13T23:29:59","modified_gmt":"2014-04-13T23:29:59","slug":"httpclient-setting-boundary-with-content-type-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/13\/httpclient-setting-boundary-with-content-type-collection-of-common-programming-errors\/","title":{"rendered":"HttpClient setting boundary with content-type-Collection of common programming errors"},"content":{"rendered":"<p>I have a bit of a messy situation that I am hoping someone can offer a solution for. So please bare with me while I offer a bit of background. Basically I am using javascript to communicate with a third party service. As part of their authentication process they need the &#8220;multipart\/form&#8221; body of the post message including an image to be encrypted in md5, this is added to a string including the date, and a few other things and then a HMAc\/SHA1 run on it. So in the end they have the multipart body, the date and the authentication hash in order to authenticate and then read the image.<\/p>\n<p>This works fine for all mobile devices except for windowsPhone .. (I know, a problem with IE&#8230; who would have thought?). their httpwebrequest does not include a &#8216;Date&#8217; header .. so no authentication. This means that I have to go native for windows phone and use the newly released httpclient code in C#. Now I am a C# noob so this is possibly where the easy solution is. I have gotten the authentication to work by passing pretty much everything to c# and just doing the post using c# but they cannot read the body because the only way I have found to send the boundary is when defining the content as multipartformDatacontent and sending the content that way changes the body so the authentication failes.<\/p>\n<p>my javascript is something like:<\/p>\n<pre><code>var boundary = \"------------ThIs_Is_tHe_bouNdaRY_\";\nvar part1Array = [];\nvar part1 = \"--\"+boundary + \"\\r\\n\"+\n    \"Content-Disposition: form-data; name=\\\"image\\\"\\r\\n\"+\n    \"Content-Type: image\/jpg\\r\\n\"+\n    \"\\r\\n\";\nvar part3Array = [];\nvar part3 = \"\\r\\n\" + boundary +\"--\";\nfor(var p1=0; p1<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have a bit of a messy situation that I am hoping someone can offer a solution for. So please bare with me while I offer a bit of background. Basically I am using javascript to communicate with a third party service. As part of their authentication process they need the &#8220;multipart\/form&#8221; body of the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6214","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6214"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6214\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}