Last post Jul 11, 2011 04:49 PM by ozkary
Jul 10, 2011 02:26 PM|yvz5|LINK
When I'm trying to log in a website and get the content I got the error below:
Content-Length or Chunked Encoding cannot be set for an operation that does not write data.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://xxx"); request.Method = "Post"; string postData = "username=" + userName + "&password=" + Password; byte arrPostDAta = System.Text.Encoding.GetEncoding(1252).GetBytes(postData); request.ContentLength = arrPostDAta.Length; System.IO.Stream strmPostData = request.GetRequestStream(); strmPostData.Write(arrPostDAta, 0, arrPostDAta.Length); strmPostData.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); this is where the error thrown.
StreamReader reader = new StreamReader(response.GetResponseStream()); string strResponse = reader.ReadToEnd(); reader.Close(); response.Close(); return strResponse;
Jul 11, 2011 04:49 PM|ozkary|LINK
This problem takes place when the server is returning an HTTP 303 which is a redirect code. The page you are posting to is redirecting to some other page and the parameters at that point are lost. You should post to the other page instead or determine why
the page is redirecting.
Use fiddler to help you see the post and return codes from the server.
please mark this as answer if it helps you.