Bug 18750 - WebClient redirected POST requests causes a bad request on the servers
Summary: WebClient redirected POST requests causes a bad request on the servers
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Martin Baulig
Depends on:
Reported: 2014-04-02 11:33 UTC by juanjo.a
Modified: 2016-11-11 10:33 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description juanjo.a 2014-04-02 11:33:09 UTC
When a webserver reply with a redirect 302 to a POST request, the redirection is handled automatically and a GET request to the new url is done, as expected, but, the previous POST data is sent again on the GET request, which is incorrect since GET requests doesn't have a body, and the server reply with an 400 Bad Request error.

Steps to reproduce:

Configure a script on a server to reply with a 302 redirect to a POST request.

Do the request:
html = wc.UploadString("http://myposturl", "var1=value1&var2=value2");

It raises exception:
{System.Net.WebException: The remote server returned an error: (400) Bad Request.
  at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) [0x00000] in <filename unknown>:0 
  at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) [0x00000] in <filename unknown>:0 }	   System.Net.WebException

The cause is that on the redirect you will see that a GET request to the new url is done, but it send on the body the post values var1=value1&var2=value2 which is not valid for a GET request. I checked it using Wireshark.

I tested it using ngixn server.

This happend with Webclient or with HttpWebRequest.
Comment 1 Martin Baulig 2016-11-11 10:33:06 UTC
This has been fixed a long time ago.