WebRequest POST with both file and parameters

前端 未结 3 1304
感动是毒
感动是毒 2021-01-02 00:07

I\'m trying to upload a file and a send along a few parameters to my site using .NET / C#. Having read a few tutorials that do either a few parameters or a file, I\'ve tried

3条回答
  •  死守一世寂寞
    2021-01-02 00:17

    The problem is that you're missing a '\n'. The following line:

    string postData = "--" + boundary + "\nContent-Disposition: form-data\n";
    

    should be:

    string postData = "--" + boundary + "\nContent-Disposition: form-data\n\n";
    

    And this line:

    postData += "\n--" + boundary + "\nContent-Disposition: form-data; name=\"file\" filename=\"upload.pdf\" Content-Type: application/pdf\n\n"
    

    is missing a '\n' before 'Content-Type'. It should be:

    postData += "\n--" + boundary + "\nContent-Disposition: form-data; name=\"file\" filename=\"upload.pdf\"\nContent-Type: application/pdf\n\n"
    

提交回复
热议问题