0

I have a webpage which has a big form(100 rows and 100 columns) and I want to post some data to that web site with a Post Request. But when i look Fiddler, this post request's content type is "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryZGLjsQc0BHm6iDFX". And here is some of the post data in this post request;

------WebKitFormBoundaryZGLjsQc0BHm6iDFX
Content-Disposition: form-data; name="__VIEWSTATE"

W+jXmq1XPrLQXBiZKXge8D3Wwt4Y4KkBWoYscKGMFVHVWIUFEP7rKy5k+T1rCleJWd9BNH1N+fad4qAPu5EYQDbywOhQ9vb6OcxwBhgktW//be6Bf67kq+yT34l8vipo

------WebKitFormBoundaryZGLjsQc0BHm6iDFX
Content-Disposition: form-data; name="__VIEWSTATEGENERATOR"

2399BEAA

And here is my post method:

public static string Post(string url, string referer, string postData, CookieContainer cookies, string contentType, string accept)
{
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
    req.Method = "POST";
    req.CookieContainer = cookies;
    req.Referer = referer;
    req.UserAgent = "";
    req.ContentType = contentType;
    req.Accept = accept;
    req.ContentLength = postData.Length;
    req.AllowAutoRedirect = false;

    Stream postStream = req.GetRequestStream();
    byte[] postBytes = Encoding.ASCII.GetBytes(postData);
    postStream.Write(postBytes, 0, postBytes.Length);
    postStream.Dispose();

    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
    cookies.Add(resp.Cookies);
    StreamReader reader = new StreamReader(resp.GetResponseStream());
    string src = reader.ReadToEnd();
    reader.Dispose(); 


    return (src);
}

So is there any way on C# to create my postData in multipart/form-data format ?

Big thx for the answers. Regards.

sagopaj
  • 133
  • 1
  • 6
  • Did you check --> https://stackoverflow.com/questions/16416601/c-sharp-httpclient-4-5-multipart-form-data-upload? Looks like a duplicate – Piotr May 07 '20 at 17:33
  • I checked that topic but they're talking about posting an image file with multipart form-data post request. But i need to post some string data not a file. So i still need help. Thx for your answer by the way. – sagopaj May 07 '20 at 23:02

0 Answers0