2017-04-12 18 views
0

나는 xamarin 웹 사이트 전체를 조사해 왔으며 webservice를 호출하는 수십 가지 방법을 찾고있다. 지금까지 튜토리얼에있는 예제를 반복 할 때마다 뭔가 잘못되었습니다. 그래서, 어떻게 내가 할 수있는 json을 반환 PHP 웹 서비스를 호출 할 수 있습니까?Xamarin.PCL 프로젝트에서 webservice를 호출하는 방법

는 여기에 내가 무슨 짓을 : 여기

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 ? ; 
      } 
     } 

답변

0

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; 
    } 
} 
또한

WebClient or httpClient 작품입니다!

using (var webClient = new System.Net.WebClient()) { 
var json = webClient.DownloadString(URL); }