I am sending an HTTP post request using HTTPWebRequest to an URL. I am sending the post data using multipart/form-data content type along with the content length of the body. However, on the server side, I am unable to retrieve the body. I can only see the headers sent. The content length of the body I sent also matches.
Why am I not able to retrieve the body.
The request method looks like this:
public void Reset(string originalFileData, string uploadLocation)
{
TcpClient client = new TcpClient();
IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(Server), portNo);
client.Connect(serverEndPoint);
string responseContent;
string serverUrl = "http://" + Server + ":" + portNo + "/abc.aspx" + "?uplvar=" + uploadLocation;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serverUrl);
request.ContentType = "multipart/form-data";
request.Method = "POST";
request.ServicePoint.Expect100Continue = false;
string postData = originalFileData;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Close();
}
Edit: I forgot to metion, I am able to retrieve the body on the first time I send the request, but on any subsequent requests I send, I am not able to retrieve it. I am creating a new connection each time I send a request. So, something might be preventing the request body from being reteieved. I am not sure why.