Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http GET request from windows phone 8

This code works on windows forms :

string URI = "http://localhost/1/index.php?dsa=232323";
string myParameters = "";

using (WebClient wc = new WebClient())
{
    wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
    string HtmlResult = wc.UploadString(URI, myParameters);
}

But i want to send http GET request from windows phone 8 . in wp 8 there are no methods UploadString() and etc...

like image 935
Gtopuria Avatar asked Nov 20 '25 01:11

Gtopuria


1 Answers

Simply use HttpClient

using(HttpClient hc = new HttpClient())
{
    var response = await hc.PostAsync(url,new StringContent (yourString));
}

And for your case, you can upload FormUrlEncodedContent content instead of forming upload string manually.

using(HttpClient hc = new HttpClient())
{
    var keyValuePairs = new Dictionary<string,string>();
    // Fill keyValuePairs

    var content = new FormUrlEncodedContent(keyValuePairs);

    var response = await hc.PostAsync(url, content);
}
like image 127
L.B Avatar answered Nov 21 '25 14:11

L.B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!