HTTP POST with HttpWebRequest

前端 未结 3 1772
北恋
北恋 2021-01-25 00:36

I\'m trying to POST some data as if I was using FORM on HTML site (ContentType = multipart/form-data). The target is amazon\'s s3. I\'m using HttpWebRequest / HttpWebResponse an

3条回答
  •  攒了一身酷
    2021-01-25 01:16

    solved! the boundary was wrong - it is needed to add 2 dashes more for post data than the value in the header has. what was needed to do in above code was:

    string boundary = "---------------------------317205771417341028";
    request.ContentType = "multipart/form-data; boundary=" + boundary;
    

    [...]

    using (Stream s = request.GetRequestStream())
    {
        boundary = "--" + boundary "\n";
    

    [...] so easy... and yet so annoying...

提交回复
热议问题