Bug 7599 - HttpWebRequest returns 404 because it reuses an old connection to a previous server
Summary: HttpWebRequest returns 404 because it reuses an old connection to a previous ...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Martin Baulig
URL:
Depends on:
Blocks:
 
Reported: 2012-10-02 17:48 UTC by Jeffrey Stedfast
Modified: 2012-10-26 17:35 UTC (History)
3 users (show)

Tags:
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:
Status:
RESOLVED FIXED

Description Jeffrey Stedfast 2012-10-02 17:48:29 UTC
I saw this last week when I was working on some code to connect to Apple's web services to add support for fetching a user's PassKit identifiers for the MonoTouch addin in MonoDevelop. I just now noticed that someone else has hit the same problem on StackOverflow:

http://stackoverflow.com/questions/12694922/https-request-to-subdomain-via-proxy-fails-with-404-response-in-mono

Both this user and myself were using https with a proxy in between (I was using the Charles proxy so that I could see what Xcode did to get the PassKit list), so it may be that both https and proxies are required for this to show itself.


In essence what I was doing was:

var request = HttpWebRequest.Create (new Uri ("https://server1.domain.com/path/to/resource"));

and once I got the info I needed from that server, I did:

var request = HttpWebRequest.Create (new Uri ("https://server2.domain.com/a/different/path"));

When this second request object sent its data to the server, I noticed in my Charles proxy logs that it was actually connecting to server1.domain.com instead of server2.domain.com and thus getting a 404 error.

The way I worked around it was by setting request.KeepAlive = false in my first case. This seemed to force the second request object to connect to the right server.
Comment 1 Martin Baulig 2012-10-20 12:55:34 UTC
I just tried with a squid proxy on Windows, using
https://en.wikipedia.org/wiki/Main_Page
and
https://de.wikipedia.org/wiki/Wikipedia:Hauptseite
and it's working fine for me.

This is my full test case:
https://github.com/baulig/Provcon-Faust/blob/599d5bb9e5c12de68d17a2da2635aace7ac55ef1/TestProxyAuth/Main.cs
Comment 2 Jeffrey Stedfast 2012-10-20 13:14:22 UTC
Yea, that's because https://de.wikipedia.org/wiki/Main_Page exists.

If the path from the second url doesn't exist on the host of the first url, then it will fail.
Comment 3 Martin Baulig 2012-10-20 16:27:00 UTC
Same thing when using
https://de.wikipedia.org/wiki/Apfel
and
https://en.wikipedia.org/wiki/Apple

Does your proxy use authentication ?  I get an exception on the 2nd request when using squid with authentication.  Works fine with non-authenticating squid, fiddler and the charles proxy.

So maybe it requires ssl and an authenticating proxy to trigger it.  However, according to that post on stackoverflow, the guy also used a proxy without authentications.
Comment 4 Jeffrey Stedfast 2012-10-20 16:53:10 UTC
I didn't have proxy authentication set either.

Btw, https://de.wikipedia.org/wiki/Apple exists, so that isn't a very good test either.

Here are the specific URLs I was requesting:

Url #1 (GET): https://daw2.apple.com/cgi-bin/clientDAW.cgi?<query string containing username & passwd>

Url #2 (POST): https://connect1.apple.com/services/P5Y9MG/viewDeveloper.action?clientId=XABBG36SBA

when connecting to Url #2, I'd get a 404 error because it tried to post to https://daw2.apple.com/services/P5Y9MG/viewDeveloper.action?clientId=XABBG36SBA

daw2.apple.com does not have that path, so it failed.


Instead of using wikipedia for both urls, try using a completely different https server for one of them that is sure to not have the path that you request in the second connection.
Comment 5 Martin Baulig 2012-10-20 17:20:55 UTC
Ok, I can reproduce this now.  You must fully read the first response or it won't work.  And it also doesn't work with any server (the URL of this bug report, https://bugzilla.xamarin.com/show_bug.cgi?id=7599, does not work).

I'm now using https://en.wikipedia.org/wiki/Apple and https://github.com/mono/mono with the Charles proxy on my Mac.

Full test case here: https://github.com/baulig/Provcon-Faust/blob/29f211d643fbdac8767ab5a95579a159e17380c0/TestProxyAuth/Main.cs

I have the feeling that this may also cause the last problem in #7248.
Comment 6 Martin Baulig 2012-10-21 15:34:56 UTC
Fixed; master d470f01, mono-2-10 d470f01, mobile-master 57d94ca.