2016-05-20 3 views
0
私はタイマーを作成する https://timercheck.io/YOURTIMERNAME/60を使用しています

、およびタイマーは、エラーコードといくつかのJSONコンテンツどのように応答HTTP 504:タイマタイムアウトJSON

これは、JSONデータのときの両方を返すためにAPIマネージャを終了するときタイマ終了:

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

タイマーがまだカウントダウン:

{"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"} 

ため、エラーコードの、私は私のAndroid上で近いVisual Studioとアプリの力にエラーが発生します。私はJSONでerrorMessageを取得したいだけです。私はVisual Studio 2015とXamarinを使ってこのプロジェクトを作っています。事前に

おかげ

UPDATE:私はあなたがいると仮定し

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

あなたのアプリから関連コードを投稿してください – Jason

+0

レスポンスのhttpステータスコードも504ですか? –

+0

@Jason ok、もう一度確認することができます – neneo

答えて

0

私は、Web応答

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

を取得し、このようにそれを呼び出すために、これを使用していますHttpClientGetStringAsyncを使用し、HttpResponseステータスコードJsonコンテンツのように504もあります。

GetStringAsyncのようなショートカットメソッドはすべて、EnsureSuccessStatusCodeを呼び出します。原因のため、504(see source here)に例外がスローされます。

あなただけの直接のGETリクエストすることができます:

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

です。もう一度確認できます。私は自分のコードを更新しました。 – neneo

0

を私はただ単にWebExceptionを使用して、このようなStatusCodeを取得し、ためにWebサービスリターンエラーコードで、私の問題に答えを見つける:

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

私はそれが最良の答えではないと思いますが、この問題から進んでいくのに役立ちます

関連する問題