代码改变世界

C# Get请求携带body

2019-04-30 18:42  若藜520  阅读(7699)  评论(5编辑  收藏  举报

 

C# get 请求携带body需要用到RestSharp,可以通过NuGet获取,但是只有.NetFramework 4.5+版本支持。通过Postman可以测试并生成C#代码

 

 

 

var client = new RestClient("https://orapi-stg.trackmeeasy.com/lomp-ext/sf-express/waybillService/getAgentNo?=");
var request = new RestRequest(Method.GET);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Connection", "keep-alive");
request.AddHeader("content-length", "202");
request.AddHeader("accept-encoding", "gzip, deflate");
request.AddHeader("Host", "orapi-stg.trackmeeasy.com");
request.AddHeader("Postman-Token", "56ca6784-0c31-4d41-b5d2-6bdcc047789a,d9873963-5dee-48f1-80d9-d672dede40f4");
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Accept", "*/*");
request.AddHeader("User-Agent", "PostmanRuntime/7.11.0");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("undefined", "{\r\n\t\"service\": \"WaybillService\",\r\n\t\"api_username\": \"erptest\",\r\n\t\"api_key\": \"78BE1BCAAED1EE08D344F894FBB296D3\",\r\n\t\"waybill\": [{\r\n\t\t\"orderid\": \"460692315855\",\r\n\t\t\"waybillno\": \"ML18082997131401_15\"\r\n\t}]\r\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

参考https://blog.csdn.net/qq_26878363/article/details/86506369