locked
IP Addresses Not Allowed With HttpClient.GetAsync?

    Question

  • I'm trying to create an app that uses HttpClient.GetAsync; I've been tearing my hair out, as I've been receiving the following error:

    A first chance exception of type 'System.Net.Http.HttpRequestException' occurred in mscorlib.dll

    When using an IP address in the GetAsync call.  When I change GetAsync to use a URL containing text, it works.  Any ideas?

    I'm new to Metro/C#, so any help / pointers will be very much appreciated....

    J

    Wednesday, April 04, 2012 9:16 PM

Answers

  • OK, after working through your suggestions, I have found the issue.  I had assumed that selecting Internet in the manifest would allow all network access.  Adding Private Networks has resolved the issue.

    Thank you so much for your time and assistance....

    • Marked as answer by IscariotJ Thursday, April 05, 2012 1:49 PM
    Thursday, April 05, 2012 1:48 PM

All replies

  • How are you using it when you use a url versus the ip address...maybe the formatting is off making it fail...

    A few things to try is just as below

    555.555.555.555 (fake ip)

    \\555.555.555.555

    http://555.555.555.555

    if port is with it just add :555 for port or whatever port number it is to the end of those...something along these lines should definitely work, if not post your usage & we'll try & help.

    for example with port...

    555.555.555.555:555 (fake ip & port)

    \\555.555.555.555:555

    http://555.555.555.555:555

    • Edited by Maya Key Wednesday, April 04, 2012 9:31 PM
    Wednesday, April 04, 2012 9:30 PM
  • Initially I was passing a string to GetAsync, but ended up with the following in order to simplify things:

    This fails with the exception:
        HttpClient httpClient = new HttpClient();
        var httpResp = await httpClient.GetAsync( "http://192.168.178.250" );

    This works:
        HttpClient httpClient = new HttpClient();
        var httpResp = await httpClient.GetAsync( "http://www.bing.com" );

    At this point, I haven't much more code then that....

    Wednesday, April 04, 2012 9:39 PM
  • if you open a command prompt and ping bing.com & use that ip what happens? it may happen that the ip your using isn't implementing http traffic on default port 80, if it's another port you must use the :port part added to the ip.

    Even if it's port 80 you should try adding the port directly...

    What effect does trying bings ip & your own with ip:port versions?

    Also \\PCNAME should work as well if it's on your network(or its your own pc as well as http://localhost:80 with or without port as well as any other version listed...

    ---Tell me which methods work if any...

    Wednesday, April 04, 2012 10:22 PM
  • If I ping both, I get a successful reply from each.  Adding the port number doesn't have any effect.  I've tried different ip's on my lan, and they all error with the same exception :(

    Thursday, April 05, 2012 6:56 AM
  • yes but when you ping bing & use the ip for bing in place of it does it work? it may not be implementing http traffic correctly or on the right port for what your using...

    what effect does using bings ip there? 65.52.107.149 is bing's ip so http://65.52.107.149 & does opening ir in IE to your own ip work?  http://192.168.178.250 ?

    opening with bing ip link bing should open like normal...in IE & other browsers...

    Thursday, April 05, 2012 1:23 PM
  • OK, after working through your suggestions, I have found the issue.  I had assumed that selecting Internet in the manifest would allow all network access.  Adding Private Networks has resolved the issue.

    Thank you so much for your time and assistance....

    • Marked as answer by IscariotJ Thursday, April 05, 2012 1:49 PM
    Thursday, April 05, 2012 1:48 PM
  • can u tell me how you solved this ip problem same happens to me please my mail id : prasanas14@gmail.com
    Thursday, July 18, 2013 7:29 AM
  • in mine ip http://10.0.0.52:8080/NpediaAnalyzrWS/login.jsp?userName=" + userName;

    shows error "An exception of type 'System.Net.Http.HttpRequestException' occurred in mscorlib.dll but was not handled in user code" but if i but 

    http://bing.com/NpediaAnalyzrWS/login.jsp?userName=" + userName;

     no error please help me 

    Thursday, July 18, 2013 7:31 AM