0
我试图从服务器获取JSON,使用HttpWebRequest。但是,尝试使用不同的JSON Im的不同网址总是会“请求超时”。这里是我的代码:响应超时xamarin android
//url = "http://46.105.85.199:3000/api/books
// Create an HTTP web request using the URL:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = WebRequestMethods.Http.Get;
request.Accept = "application/json";
request.ContentType = "application/json";
request.Timeout = 300000;
var response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string output = reader.ReadToEnd();
response.Close();
return output;`
和JSON:
[
{
"metaData": {
"title": "Гарри Поттер и Принц-полукровка (Росмэн) -0",
"language": "ru",
"date": "2005",
"creator": "Джоан Кэтлин Роулинг",
"creatorFileAs": "Джоан Кэтлин Роулинг",
"publisher": "РОСМЭН",
"description": "",
"subject": "child_adv"
},
"chapters": [
{
"id": "cover",
"href": "OEBPS/cover.xhtml",
"media-type": "application/xhtml+xml"
},
...
],
"name": "legion.epub",
"url": "/upload/common/legion.epub",
"lastMark": null,
"cover": "./client/upload/images/missing.jpg",
"id": 8,
"readerId": null,
"teamId": null
}
]
等。我也尝试通过ID和章节获得书籍,但获得相同的结果。
是的。问题出现在'章节'JSON被添加到响应中时。 –
@LukaBaryshych我不太明白你的意见,你说当你从个人电脑请求时,响应速度很快,对不对?然后你说当问题出现在服务器动作中时,问题就出现了,对吗?我不明白。无论哪种方式,答案都被接受了吗? –
编写客户端时,它使用简单的JSON。然后,API被更改(添加了“章节”),客户分手了。看起来问题出在服务器上,因为我可以从PC获取响应,但不能从我的智能手机获取响应。 –