【发布时间】:2016-05-15 12:21:58
【问题描述】:
我正在尝试使用 HttpWebRequest 从服务器获取 JSON。但是,尝试使用不同 JSON 的不同 url 我总是得到“请求超时”。这是我的代码:
//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 和章节获取 book,但结果相同。
【问题讨论】: