HttpWebRequest and WebProxy to get json from url – tizen 4 galaxy watch
HttpWebRequest and WebProxy to get json from url – tizen 4 galaxy watch
BY 01 Oct 2019Tizen .NET
Hi! I’m try to get json from url (stop_url) without success. When it tries to set webproxy (line 14), it gives me an exception(line 48) “Invalid URI: The hostname could not be parsed.“. Code below:
if (!stop_url_.Equals(""))
{
string html = null;
try
{
ConnectionItem currentConnection = ConnectionManager.CurrentConnection;
Console.WriteLine("connection(" + currentConnection.Type + ", " + currentConnection.State);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(stop_url_);
//request.ContentType = "application/json";
// When a watch is paired with a mobile device, we can use WebProxy.
if (currentConnection.Type == ConnectionType.Ethernet)
{
string proxyAddr = ConnectionManager.GetProxy(AddressFamily.IPv4);
WebProxy myproxy = new WebProxy(proxyAddr, true);
request.Proxy = myproxy;
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Console.WriteLine("StatusDescription: " + ((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine("responseFromServer :" + responseFromServer);
// Clean up the streams and the response.
reader.Close();
response.Close();
html = responseFromServer;
Console.WriteLine(html);
}
else
{
WebClient wc = new WebClient();
html = wc.DownloadString(stop_url_);
Console.WriteLine(html);
}
//Se ho scaricato correttamente l'html
if (html != null && !html.Equals("")) doc = NSoupClient.Parse(html);
else time_error = -1; //connection error
}
catch (Exception ex)
{
Console.WriteLine("An error occurs : " + ex.Message);
}
}
HttpWebRequest and WebProxy to get json from url – tizen 4 galaxy watch
Hi! I’m try to get json from url (stop_url) without success. When it tries to set webproxy (line 14), it gives me an exception(line 48) “Invalid URI: The hostname could not be parsed.“. Code below:
Any suggest?
BY
16 Apr 2025
Tizen Studio
BY
04 Nov 2024
Tizen Studio
BY
02 Apr 2024
Tizen Studio