从代码隐藏调用ASP.NET Web API
发布时间:2020-12-05 02:46:13 所属栏目: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:将内容注入所有Response流
- asp.net-mvc – mvc razor @helper可以返回非编码标签吗?
- 有标签的ASP.NET WebControl吗?
- asp.net – 如何查看Chrome开发者工具中发布到表单的数据大
- asp.net-mvc – 在ASP.NET身份中角色与声明的最佳实践
- 实体框架 – WebApi OData:$filter’any’或’all’查询不
- asp.net – 获得“System.Web.Mvc.Html.MvcForm”一页
- asp.net-mvc – 在MVC Razor视图中使用@RenderBody有什么意
- asp.net-mvc – MVC导航到不同的控制器视图
- asp.net-core – ASP.Net核心maxUrlLength
推荐文章
站长推荐
- asp.net – 如何从WCF客户端拦截raw soap reques
- asp.net-mvc-3 – 方法“OrderBy”必须在方法“跳
- asp.net-mvc – 我如何可以渲染局部视图在asp.ne
- asp.net-mvc – ASP.NET MVC应用程序的WatiN最佳
- asp.net-mvc – 不要在ASP .NET MVC 4 BundleCon
- asp.net-mvc – ASP.NET MVC WebSite中的ERR_EMP
- asp.net-mvc – 在Azure Active Directory B2C中
- asp.net-mvc – 使用Asp.net MVC 4中的OutputCac
- asp.net-mvc – 带有asp.net mvc 4和EntityFrame
- asp.net – 如何正确过滤数据表(datatable.selec
热点阅读