我正在尝试从网站获取一些数据,首先尝试使用 localhost。但获取请求失败。将其更改为 POST 工作正常。
Error: The Resource cannot be found.
控制器动作:
[HttpGet()]
public ActionResult GetInformation(string id)
{
Uri uri = new Uri("http://localhost:65076/ShowDetails?id=" + id);
HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Get;
HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string tmp = reader.ReadToEnd();
response.Close();
return Json(new { data = tmp });
}
JavaScript 函数:
function getInformation() {
var link = '/Home/GetInformation';
var id = '11111';
$.ajax({
type: 'GET',
url: link,
data: { id: id },
dataType: 'json',
success: function (result) {
$.each(result.data, function (item, value) {
...
});
},
error: function (result) {
...
}
});
};