locked
WebRequest to IP address RRS feed

  • Question

  • Hi,

    I try to develop application (C# - UWA) which will connect to server (REST) and get response (data).

    I have code :

    class RestRequest
        {
            public async Task<string> RESTQuery (string devicequery)
            {
                string responce = string.Empty;
                WebRequest Rrequest = WebRequest.Create(devicequery);     
                Rrequest.Method = "GET";
                Rrequest.ContentType= "application/json";
                Rrequest.Credentials = CredentialCache.DefaultCredentials;
                
                WebResponse Rresponce = await Rrequest.GetResponseAsync(); 
                Stream RestStream = Rresponce.GetResponseStream();          
                StreamReader ReadResponceFromStream = new StreamReader(RestStream);
                responce = ReadResponceFromStream.ReadToEnd();
                RestStream.Dispose();
                ReadResponceFromStream.Dispose();
                Rresponce.Dispose();
                return responce;
            }
                
        }

    and its working fine for web when request is for example http://www.google.com

    But i like to make request to my REST server located in my home network (192.168.0.105), when i try, i get following error:

    "Invalid URI: The Authority/Host could not be parsed"

    Is there any way to use IP address to execute request or i should find different way to get data from REST server ?

     BR


    Piotr

    Tuesday, November 15, 2016 8:23 PM

Answers

  • Try to put http:// in front of the actual IP address:

    string response = await RESTQuery("http://192.168.0.105");

    You probably already know that 192.168.0.105 is not a public IP address.

    What is the difference between public and private IP address?: https://www.iplocation.net/public-vs-private-ip-address

    You should be able to discover what you public IP address is by browsing to the following website: https://www.whatismyip.com/what-is-my-public-ip-address/

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread

    • Marked as answer by Piotr_Kowalski Tuesday, November 15, 2016 9:04 PM
    Tuesday, November 15, 2016 8:37 PM

All replies

  • Try to put http:// in front of the actual IP address:

    string response = await RESTQuery("http://192.168.0.105");

    You probably already know that 192.168.0.105 is not a public IP address.

    What is the difference between public and private IP address?: https://www.iplocation.net/public-vs-private-ip-address

    You should be able to discover what you public IP address is by browsing to the following website: https://www.whatismyip.com/what-is-my-public-ip-address/

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread

    • Marked as answer by Piotr_Kowalski Tuesday, November 15, 2016 9:04 PM
    Tuesday, November 15, 2016 8:37 PM
  • Thanks Magnus,

    Its still not working for my server but for 74.125.127.100 working fine, so problem is on my server site.

    BR


    Piotr

    Tuesday, November 15, 2016 9:07 PM