从代码隐藏调用ASP.NET Web API
发布时间:2020-12-05 04:50:31 所属栏目:asp.Net 来源:互联网
导读:我如何直接从代码隐藏调用ASP.NET Web API?还是应该调用我的 javascript函数,从代码隐藏中调用get JSON方法? 我通常有如下的东西: function createFile() { $.getJSON(api/file/createfile, function (data) { $(#Result).ap
我如何直接从代码隐藏调用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 – System.Security.SecurityException?
- 在ASP.NET MVC4中是否可以将C#或VB函数标记为Javascript?
- asp.net-mvc – ASP.NET MVC WebSite中的ERR_EMPTY_RESPONS
- asp.net – 使用FormsAuthentication持久的cookie超时
- asp.net – 在我的网站中添加HttpModule时出现“500内部服务
- Asp.NetCore1.1版本去掉project.json后如何打包生成跨平台包
- asp.net-mvc – ie9:调试时出现恼人的弹出:“错误:’__f
- 什么用于ASP.NET的成员资格
- asp.net使用DataTable构造Json字符串的方法
- .net – Viewstate隐藏字段如此之大,一切都会崩溃
推荐文章
站长推荐
- asp.net-mvc-3 – ASP.net MVC – 模型绑定不包括
- asp.net – 从多个Web.config文件访问appSetting
- asp.net-mvc – 已经使用相同的参数类型定义了一
- asp.net使用H5新特性实现异步上传的示例
- asp.net-mvc – 模型单元测试能否真正独立,如何[
- asp.net-mvc – ASP.NET MVC 3 Treeview
- 并行运行ASP.NET Webforms和ASP.NET MVC
- asp.net-web-api – 在ASP.NET Web API控制器的n
- asp.net – 如何查看Chrome开发者工具中发布到表
- asp.net – 我如何使用AJAX来确定用户的会话是否
热点阅读