1

I'm trying to use the Windows.Web.Http.HttpClient class but it keeps throwing me an 404 error, even if I try the code from the doc :

var uri = new Uri("http://example.com/datalist.aspx");
var httpClient = new HttpClient();

try
{
    var result = await httpClient.GetStringAsync(uri);
    Debug.WriteLine("content : {0}", result);
}
catch (Exception e)
{
    Debug.WriteLine("error : {0}", e.Message);
}

And this is the error :

A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
error : Not found (404).

Response status code does not indicate success: 404 (Not Found).

link of the doc I used

I can access the address from the phone with a web browser like IE.

3
  • Perhaps the url you are trying to access checks specific headers? Visit that page while Fiddler is running and mimic the headers in your code. Commented Apr 21, 2015 at 14:30
  • 1
    It should return 404, the fact that you can browse to an URL in a webbrowser does not guarantee it returns 200 or another "OK" status code. If you go to the url with a HTTP sniffer like Fiddler running you will see the server returns 404 when navigating to this URL while still sending a response body. Commented Apr 21, 2015 at 14:50
  • Yes, that the mistake I made. I just checked with web browser in the first place. Commented Apr 21, 2015 at 14:57

1 Answer 1

2

That's because it does return a 404 (use a sniffer and check).

Change the url to http://www.example.com and things will work.

The site returns the same response on all requests. You can try:

http://www.example.com/mynickistuff.abcd
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.