【发布时间】:2016-05-20 08:39:03
【问题描述】:
我正在使用https://timercheck.io/YOURTIMERNAME/60 创建计时器,当计时器结束时,API 管理器会返回错误代码和一些 JSON 内容
这是定时器结束时的 JSON 数据:
{"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"}
由于错误代码,我在 Visual Studio 上遇到错误,并且在我的 Android 上强制关闭应用程序。我只想在 JSON 中获取 errorMessage。我正在使用 Visual Studio 2015 和 Xamarin 来制作这个项目。
提前致谢
更新:
我正在使用它来获取网络响应
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;
}
}
}
然后这样称呼它:
CekTimer dataWaktu = JsonConvert.DeserializeObject<CekTimer>(await FetchUserAsync(url));
【问题讨论】:
-
请从您的应用中发布相关代码
-
响应的http状态码也是504吗?
-
@Jason 好的,你可以再检查一下
-
@KaiBrummund 是的,http 的响应是 504
标签: c# android api xamarin visual-studio-2015