Http Post error (405) Method Not Allowed.

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

I'm trying to test code to post xml to a web page in anticipation of a new
project. I wanted to try a simple test first, but I get a (405) Method Not
Allowed error no matter what I try.
I have tried posting to the same machine as well as a different machine.
Anonymous access is enabled for the virtual directory.
I have added Allow POST for All Users for the virtual directory. I tried
allow All verbs for all users but the system said that was already in place.

Here is the code:
The destination url is http://localhost/XmlPost/XmlPost.html (as an
alternative I created the same setup on another machine). It doesnt do
anything.
The xml string is a simple xml block hard coded in the code for testing
purposes.
byte[] bytes = Encoding.UTF8.GetBytes(xml);
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.Method = "POST";
request.ContentLength = bytes.Length;
request.ContentType = "text/xml";
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
}
try
{
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
}
catch (WebException webEx)
{
this.Label3.Text = webEx.Message;
}

All changes I have tried have no effect and I cannot find anything on the
forums or google so far that has helped.
 
Thus wrote Eric,
I'm trying to test code to post xml to a web page in anticipation of a
new
project. I wanted to try a simple test first, but I get a (405)
Method Not
Allowed error no matter what I try.
I have tried posting to the same machine as well as a different
machine.
Anonymous access is enabled for the virtual directory.
I have added Allow POST for All Users for the virtual directory. I
tried
allow All verbs for all users but the system said that was already in
place.
Here is the code:
The destination url is http://localhost/XmlPost/XmlPost.html (as an
alternative I created the same setup on another machine). It doesnt do
anything.

And that's the problem. You cannot post to a static HTML page. What's that
supposed to do? Replace the HTML page with an ASP.NET page.

Cheers,
 
Well, actually, you can post to an HTML page, for example, the .html could
be a CMS site or a site that works with perl or other such script... It
could even have been mapped to use the .net stuff from within IIS.

However, one issue that you could have is that the XML code itself is being
stopped by the security for your app. If your destination page is actually a
remapped .aspx page, then in your page directive at the top (for your
destination page), you will need validateRequest="false"

However, doing this will allow scripts and whatnot to be saved into the
page. It is disabled by default to prevent cross site scripting. If you are
happy with it, then that is how you would do it.

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
Thus wrote David,
Well, actually, you can post to an HTML page, for example, the .html
could be a CMS site or a site that works with perl or other such
script... It could even have been mapped to use the .net stuff from
within IIS.

You cannot post to a physical HTML *page*. You can post to a server side
application module that happens to be mapped to the *.html extension, which
I assumed isn't the case here.
However, one issue that you could have is that the XML code itself is
being stopped by the security for your app. If your destination page
is actually a remapped .aspx page, then in your page directive at the
top (for your destination page), you will need validateRequest="false"

The OP's code doesn't post form data, but plain old XML. Request validation
doesn't apply here.

Cheers,
 
Back
Top