java restsharp_如何在asp.net核心中使用RestSharp.NetCore (How to use RestSharp.NetCore in asp.net core)...
英文原文
There's an existing StackOverflow question and example that calls ExecuteAsync on RestSharp.NetCore.
I successfully used that example when referencing RestSharp.NetCore 105.2.3 with Newtonsoft.Json 9.0.2-beta2.
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using RestSharp;
public async Task TestPost(ObjectFoo foo)
{
JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings {
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
RestClient restClient = new RestClient(API_URL);
RestRequest request = new RestRequest("SOME_METHOD", Method.POST);
request.AddHeader("Accept", "application/json");
string jsonObject = JsonConvert.SerializeObject(foo, Formatting.Indented, jsonSerializerSettings);
request.AddParameter("application/json", jsonObject, ParameterType.RequestBody);
TaskCompletionSource taskCompletion = new TaskCompletionSource();
RestRequestAsyncHandle handle = restClient.ExecuteAsync(
request, r => taskCompletion.SetResult(r));
RestResponse response = (RestResponse)(await taskCompletion.Task);
return JsonConvert.DeserializeObject(response.Content);
}
中文翻译
现有的StackOverflow问题和示例在RestSharp.NetCore上调用ExecuteAsync。
在使用Newtonsoft.Json 9.0.2-beta2引用RestSharp.NetCore 105.2.3时,我成功使用了该示例。
使用System.Threading.Tasks;
使用Newtonsoft.Json;
使用Newtonsoft.Json.Serialization;
使用RestSharp;
public async Task< SomeObject> TestPost(ObjectFoo foo)
{
JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings {
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
RestClient restClient = new RestClient(API_URL);
RestRequest request = new RestRequest(" SOME_METHOD" ,Method.POST);
request.AddHeader(" Accept" ," application / json" );
string jsonObject = JsonConvert.SerializeObject(foo,Formatting.Indented,jsonSerializerSettings);
request.AddParameter(" application / json" ,jsonObject,ParameterType.RequestBody);
TaskCompletionSource< IRestResponse> taskCompletion = new TaskCompletionSource< IRestResponse>();
RestRequestAsyncHandle handle = restClient.ExecuteAsync(
请求,r => taskCompletion.SetResult(R));
RestResponse response =(RestResponse)(等待taskCompletion.Task);
返回JsonConvert.DeserializeObject< SomeObject>(response.Content);
}
There's an existing StackOverflow question and example that calls ExecuteAsync on RestSharp.NetCore.
I successfully used that example when referencing RestSharp.NetCore 105.2.3 with Newtonsoft.Json 9.0.2-beta2.
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using RestSharp;
public async Task TestPost(ObjectFoo foo)
{
JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings {
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
RestClient restClient = new RestClient(API_URL);
RestRequest request = new RestRequest("SOME_METHOD", Method.POST);
request.AddHeader("Accept", "application/json");
string jsonObject = JsonConvert.SerializeObject(foo, Formatting.Indented, jsonSerializerSettings);
request.AddParameter("application/json", jsonObject, ParameterType.RequestBody);
TaskCompletionSource taskCompletion = new TaskCompletionSource();
RestRequestAsyncHandle handle = restClient.ExecuteAsync(
request, r => taskCompletion.SetResult(r));
RestResponse response = (RestResponse)(await taskCompletion.Task);
return JsonConvert.DeserializeObject(response.Content);
}
现有的StackOverflow问题和示例在RestSharp.NetCore上调用ExecuteAsync。
在使用Newtonsoft.Json 9.0.2-beta2引用RestSharp.NetCore 105.2.3时,我成功使用了该示例。
使用System.Threading.Tasks;
使用Newtonsoft.Json;
使用Newtonsoft.Json.Serialization;
使用RestSharp;
public async Task< SomeObject> TestPost(ObjectFoo foo)
{
JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings {
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
RestClient restClient = new RestClient(API_URL);
RestRequest request = new RestRequest(" SOME_METHOD" ,Method.POST);
request.AddHeader(" Accept" ," application / json" );
string jsonObject = JsonConvert.SerializeObject(foo,Formatting.Indented,jsonSerializerSettings);
request.AddParameter(" application / json" ,jsonObject,ParameterType.RequestBody);
TaskCompletionSource< IRestResponse> taskCompletion = new TaskCompletionSource< IRestResponse>();
RestRequestAsyncHandle handle = restClient.ExecuteAsync(
请求,r => taskCompletion.SetResult(R));
RestResponse response =(RestResponse)(等待taskCompletion.Task);
返回JsonConvert.DeserializeObject< SomeObject>(response.Content);
}
java restsharp_如何在asp.net核心中使用RestSharp.NetCore (How to use RestSharp.NetCore in asp.net core)...相关推荐
- java baseentity_如何在JPA的BaseEntity中实现equals()和hashcode()方法?
我有一个BaseEntity类,它是我的应用程序中所有JPA实体的超类. @MappedSuperclass public abstract class BaseEntity implements S ...
- java spring license_java-如何在Spring Boot Application中解决FlyWay许可问题
使用FlyWay企业许可证的我的Spring Boot应用程序无法启动,并显示以下消息: Caused by: org.flywaydb.core.api.FlywayException: Missi ...
- ASP.NET核心之路微服务第03部分:Identity
目录 介绍 文章系列 安装ASP.NET Core Identity 配置ASP.NET Core Identity 管理用户数据 使用Microsoft帐户,Google,Facebook等登录 结 ...
- ASP.NET核心之路微服务第02部分:查看组件
目录 文章系列 介绍 部分视图vs. 视图组件 用视图组件替换购物篮(Basket) 部分视图 用视图组件替换Catalog部分视图 用户通知计数器 结论 下载Part02.zip 文章系列 AS ...
- 在ASP.NET页面中实现数据柱状图
棒图有时又称为"Bar"图,在ASP.NET中拥有了一个新功能--绘图功能,通过此功能就能够按照要实现的图表的模样来绘制,最后在客户端的浏览器中形成一个图片,从而显示出图表来. 本 ...
- [MVC]Asp.net MVC中的Session
[MVC]Asp.net MVC中的Session 2008年12月9日 分类: ASP.NET, ASP.NET MVC, C#, 开发笔记 最近使用ASP.NET MVC 中的Controller ...
- 如何在 ASP.NET MVC 中集成 AngularJS(2)
在如何在 ASP.NET MVC 中集成 AngularJS(1)中,我们介绍了 ASP.NET MVC 捆绑和压缩.应用程序版本自动刷新和工程构建等内容. 下面介绍如何在 ASP.NET MVC 中 ...
- 如何在 ASP.NET MVC 中集成 AngularJS
介绍 当涉及到计算机软件的开发时,我想运用所有的最新技术.例如,前端使用最新的 JavaScript 技术,服务器端使用最新的基于 REST 的 Web API 服务.另外,还有最新的数据库技术.最新 ...
- eclipse java luna,java-如何在Eclipse Luna中配置Lombok
java-如何在Eclipse Luna中配置Lombok 我使用Maven在Eclipse Luna中配置了龙目岛. 注释已正确添加,但没有生成getter和setter. eclipse.ini ...
- 如何在 ASP.NET MVC 中集成 AngularJS(3)
今天来为大家介绍如何在 ASP.NET MVC 中集成 AngularJS 的最后一部分内容. 调试路由表 - HTML 缓存清除 就在我以为示例应用程序完成之后,我意识到,我必须提供两个版本的路由表 ...
最新文章
- 域名后缀php做跳转首页,手机移动端网站和电脑PC端网站域名使用与跳转PHP代码...
- ActiveState Komodo IDE v5.2.1.34168 最新版for Linux/Mac OS/Windows 全5大平台
- 以太坊怎么注册_以太坊2.0将至,牛市即将到来??
- 微软并行编程类库Parallel Extensions初探 Part1
- egret3D与2D混合开发,画布尺寸不一致的问题
- scala学习手记28 - Execute Around模式
- 前端学习(2948):webpack创建简单项目
- Navicat工具导出Mysql数据表结构到Excel文件中
- 信息学奥赛一本通(1202:Pell数列)
- Trip to America for 3 more months
- java list 取两条_java list集合中有多条数据随机两条一组
- 每天快走一小时,身体会有什么变化?
- Q145: 三次曲线对比及其矩阵表示(Bezier, B-Spline, Hermite, Catmull-Rom)
- iOS下载文件,保存路径. 防止加到iCloud备份
- 996.ICU凉凉了!
- 剑指offer(28)—数组中出现次数超过一半的数字
- Fortran笔记,全局变量
- java中类的main方法总结
- python制作mcmod_[周边教程]MinecraftMOD制作_从入门到精通
- English improvement of IT Test(2016)
热门文章
- 解决putty自动断开问题
- 自学Shiro框架笔记
- win10pe系统计算机名修改,pe 重置win10登陆密码怎么操作_如何用pe系统重置win10电脑密码-win7之家...
- python3.4编程,麻瓜编程·python实战·4-3自学:给4-2作业换新界面
- 使用GoldWave为音频添加特效
- xv6 Traps, interrupts, and drivers
- 使用exceljs导出excel表格
- python调用通达信函数大全_通达信dll开发实例,使用python在通达信里面选股
- OPPO手机刷机解锁救砖解账户锁方法
- 解决vscode下载很慢的问题