Riv*_*vka 9 asp.net webforms getjson asp.net-web-api
如何直接从代码隐藏调用ASP.NET Web API?或者我应该调用从代码隐藏调用getJSON方法的javascript函数?
我通常有类似的东西:
function createFile() {
$.getJSON("api/file/createfile",
function (data) {
$("#Result").append('Success!');
});
}
Run Code Online (Sandbox Code Playgroud)
任何指针赞赏.TIA.
*我正在使用WebForms.
Eri*_*ing 13
如果您必须自己调用Web服务,可以HttpClient 按照Henrik Neilsen的说明尝试使用.
一个基本的例子:
// Create an HttpClient instance
HttpClient client = new HttpClient();
// Send a request asynchronously continue when complete
client.GetAsync(_address).ContinueWith(
(requestTask) =>
{
// Get HTTP response from completed task.
HttpResponseMessage response = requestTask.Result;
// Check that response was successful or throw exception
response.EnsureSuccessStatusCode();
// Read response asynchronously as JsonValue
response.Content.ReadAsAsync<JsonArray>().ContinueWith(
(readTask) =>
{
var result = readTask.Result
//Do something with the result
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25632 次 |
| 最近记录: |