Hello there, I need to simply push some text to my webserver from my galaxy watch app. I found that it could be done simply by:
using System.Net;
try
{
WebClient client = new WebClient();
string result = client.UploadString("my_url_web_page", "test");
}
catch (WebException ex)
{
DisplayAlert("error", "" + ex.Message, "OK");
}
but this I always get error Resource temporarily unavailable.
Can someone give me a hint what I do wrong?
Hello,
Please add the ‘internet’ privilege on the tizen manifest if you haven’t added it already.
Ping the URL from the device by any other means to ensure that the web resources are available from the device.
Best Regards,
Armaan Ul Islam
Samsung Developer Program
Hi, thanks, that works, but not 100% as should. And how can I ping the url?
I have another code:
try
{
string url = "https://www.#####.com/test.php";
string postData = "key=value&test=1";
// converting string to bytes for stream
byte[] postDataStream = Encoding.UTF8.GetBytes(postData);
WebRequest request = WebRequest.Create(url);
request.Method = "POST";
request.ContentLength = postDataStream.Length;
request.ContentType = "application/x-www-form-urlencoded";
// writing post data to request stream
Stream dataStream = request.GetRequestStream();
dataStream.Write(postDataStream, 0, postDataStream.Length);
dataStream.Close();
// fetching response
WebResponse webResponse = request.GetResponse();
Stream webStream = webResponse.GetResponseStream();
// if response is to big, we need to read is as stream
StreamReader reader = new StreamReader(webStream);
string data = reader.ReadToEnd();
}
catch (Exception ex)
{
await DisplayAlert("ex", "" + ex, "OK");
}
This code works only for specific website, so I suppose, some hostings are some firewalls or something, what blocking this curl post. Simply - I try two URL (two different hosting providers) - one work / another not. Hosting providers can´t help me withou some errors.
So my new question is - can someone help me, how to show error message? I already have this code in try / catch but I dont get any errors. When I run this code, whole app frozen.