I am using HttpWebRequest for POST data on an ASP.NET web page (currently running on an ASP.NET development server). Here is the code;
string url = "http://localhost:3333/MySite/"; WebResponse response = null; try { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); ASCIIEncoding encoding = new ASCIIEncoding(); string postData = "data=test"; byte[] dataBtyes = encoding.GetBytes(postData); request.UserAgent = "Custom Agent"; request.Method = "POST"; request.KeepAlive = true; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = dataBtyes.Length; Stream stream = request.GetRequestStream(); stream.Write(dataBtyes, 0, dataBtyes.Length); stream.Close(); response = request.GetResponse(); } catch (Exception e) { }
Using the HTTPModule, I intercept requests from the "User Agent" and send my own custom header. This works great for GET requests, however the data I want to send could potentially exceed the limits allowed for GET requests, so I would like to use POST (as mentioned above).
I tested this code on a real IIS server and it works, however the Visual Studio development server throws a "405 Method Not Allowed" exception every time GetResponse () is called after sending the POST data (GET works fine).
Can someone give an explanation why the development server seems to be rejecting POST requests?
Editing: The question title and body are updated to emphasize the problem associated with the VS dev server.
source share