2016-05-20 6 views
0

ich https://timercheck.io/YOURTIMERNAME/60 bin mit Timer zu erstellen, und wenn der Timer den API-Manager beendet wird sowohl einen Fehlercode und einigen JSON InhaltWie Antwort HTTP 504: Timer Time Out JSON

Dies ist die JSON-Daten zurück, wenn Timer Ende:

{"errorMessage":"504: timer timed out"} 

Wenn der Timer noch Countdown:

{"timer":"neo308CCEACbid","request_id":"e54f484e-1e64-11e6-9552-3950b2ec2d5c","status":"ok","now":1463732937,"start_time":1463732935,"start_seconds":180,"seconds_elapsed":2,"seconds_remaining":178,"message":"Timer still running"} 

Wegen des Fehlercode, i Fehler auf Visual Studio und App Kraft schließt auf meinem Android bekommen. Ich möchte nur die errorMessage in JSON erhalten. Ich verwende Visual Studio 2015 und Xamarin, um dieses Projekt zu erstellen.

Vielen Dank im Voraus

UPDATE:

Ich verwende diese Web-Antwort

private async Task<string> FetchUserAsync(string url) 
     { 
      // Create an HTTP web request using the URL: 
      HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); 
      request.ContentType = "application/json"; 
      request.Method = "GET"; 

      // Send the request to the server and wait for the response: 
      using (WebResponse response = await request.GetResponseAsync()) 
      { 
       // Get a stream representation of the HTTP web response: 
       using (var sr = new StreamReader(response.GetResponseStream())) 
       { 
        string strContent = sr.ReadToEnd(); 
        return strContent; 
       } 
      } 
     } 

Und nennen Sie es wie folgt zu erhalten:

CekTimer dataWaktu = JsonConvert.DeserializeObject<CekTimer>(await FetchUserAsync(url)); 
+0

bitte den entsprechenden Code aus Ihrer App – Jason

+0

Ist der HTTP-Statuscode der Antwort auch ein 504? –

+0

@Jason ok, können Sie noch einmal überprüfen – neneo

Antwort

0

Ich nehme an, Sie sind mit HttpClient und GetStringAsync, und dass die HttpResponse Statuscode ist auch ein 504, wie im JSON Content.

Die Shortcut-Methoden wie GetStringAsync alle rufen EnsureSuccessStatusCode, die Ursache eine Ausnahme auf einem 504 wirft (see source here).

Sie können nur eine direkte GET-Anfrage machen:

var client = new HttpClient(); 
var response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, yourUri)); 
var json = await response.Content.ReadAsStringAsync(); 
+0

können Sie erneut überprüfen, ich habe meinen Code aktualisiert – neneo

0

ich die Antwort meines Problems gefunden, wegen webservice Rückkehr Fehlercode, einfach nur WebException verwenden und die StatusCode wie diese:

private async Task<string> FetchUserAsync(string url) 
       { 
        try 
        { 
         // Create an HTTP web request using the URL: 
         HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); 
         request.ContentType = "application/json"; 
         request.Method = "GET"; 

         // Send the request to the server and wait for the response: 
         using (WebResponse response = await request.GetResponseAsync()) 
         { 
          // Get a stream representation of the HTTP web response: 
          using (var sr = new StreamReader(response.GetResponseStream())) 
          { 
           string strContent = sr.ReadToEnd(); 
           return strContent; 
          } 
         } 
        } 
        catch (WebException e) 
        { 
         string a = ((HttpWebResponse)e.Response).StatusCode.ToString(); 
//Toast.MakeText(this, a, ToastLength.Long).Show(); 
         if (a == "GatewayTimeout") 
         { 
          return "{'errorMessage':'504: timer timed out'}"; 
         } 
         else 
         { 

          internetDropDialog(); 
          return ""; 
         } 
        } 
       } 

Ich denke, es ist nicht die beste Antwort, aber es kann Ihnen helfen, von diesem Problem weiterzugehen