HTTP POST with HttpWebRequest

前端 未结 3 1770
北恋
北恋 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 00:57

    I spent about three days straight trying to solve the same issue. Make absolutely sure you use consistent line endings for your POST body format. I forgot a single carriage return (\r) in a CRLF sequence and Amazon S3 gave me this error and similar ones.

    0 讨论(0)
  • 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...

    0 讨论(0)
  • 2021-01-25 01:20

    POST that to your own server not Amazon, and then check the POST - I will bet that your headers are not set correctly, meaning that because you are using multipart form-data, the POST can't be decoded.

    You should use the official SDK anyway.

    http://aws.amazon.com/sdkfornet/

    0 讨论(0)
提交回复
热议问题