从代码隐藏调用ASP.NET Web API
发布时间:2020-12-15 20:27:21 所属栏目:asp.Net 来源:网络整理
导读:我如何直接从代码隐藏调用ASP.NET Web API?还是应该调用我的 javascript函数,从代码隐藏中调用get JSON方法? 我通常有如下的东西: function createFile() { $.getJSON("api/file/createfile",function (data) { $("#Result").append('Success!'); }); }
我如何直接从代码隐藏调用ASP.NET Web API?还是应该调用我的
javascript函数,从代码隐藏中调用get
JSON方法?
我通常有如下的东西: function createFile() { $.getJSON("api/file/createfile",function (data) { $("#Result").append('Success!'); }); } 任何指针赞赏. TIA. *我正在使用WebForms. 解决方法
如果您必须调用Web服务本身,您可以尝试使用HttpClient
as described by Henrik Neilsen.
Updated HTTPClient Samples 一个基本的例子: // 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 }); }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 表单和JSON调用中的表单
- asp.net-mvc – 是否可以在Visual Studio 2013中使用asp.ne
- asp.net-mvc – 强大的自托管服务器的最佳选择:WCF与ASP.N
- asp.net – Microsoft成员提供者与自定义提供者vs完成自定义
- asp.net-mvc – 在ASP.NET MVC中的Controller内生成URL
- 为什么asp.net将页面包装在一个表单中?
- asp.net-mvc – 如何防止HttpUnauthorizedResult(401)重定向
- asp.net – 发送多个模型以查看MVC 4
- 为什么每个人都在ASP.NET Webforms中依赖注入是困难的,当Pa
- IIS 7中为ASP.NET缺少MIME类型404.17
推荐文章
站长推荐
热点阅读