0

I've been looking all over the xamarin website and ther is dozens of way to call a webservice. Until now, each time i try to repeat the example that is in the tutorial, something goes wrong. So, how can I simply call a php webservice that returns me a json that I can work with ?

Here is what I did:

 private async Task<JsonValue> Connexion_Webservice(string url)
        {
            // Creates the HTTP Request
            HttpWebRequest requete = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
            requete.ContentType = "application/json";
            requete.Method = "GET";


            //Sends the request and wait for the response
            using (WebResponse response = await requete.BeginGetResponse()
            {
             // until here I dont know what to do, what should I do ?   ;
            }
        }
En_Tech_Siast
  • 83
  • 1
  • 12

1 Answers1

0

Here is sample

  using (WebResponse response = await request.GetResponseAsync ())
{
    // Get a stream representation of the HTTP web response:
    using (Stream stream = response.GetResponseStream ())
    {
        // Use this stream to build a JSON document object:
        JsonValue jsonDoc = await Task.Run (() => JsonObject.Load (stream));
        Console.Out.WriteLine("Response: {0}", jsonDoc.ToString ());

        // Return the JSON document:
        return jsonDoc;
    }
}

Also WebClient or httpClient works!

using (var webClient = new System.Net.WebClient()) {
var json = webClient.DownloadString(URL);  }
Community
  • 1
  • 1
Max CHien
  • 133
  • 1
  • 8