[英]RestSharp Array Request
发送数组帖子RestSharp吗? 字典,List <>是否不兼容?
public class Test
{
public string key { get; set; }
public string viewType { get; set; }
public string module { get; set; }
public string method { get; set; }
public Dictionary<string, string> parameters { get; set; }
}
我的班级初始化。
Test t = new Test();
t.key = "xxxxxxxxxxxxxxxxxx";
t.viewType = "json";
t.module = "test";
t.method = "test";
t.parameters = new Dictionary<string,string>();
t.parameters.Add("p1", "data1");
发送数据请求
IRestResponse response = restClient.Execute<Test>(restRequest);
发送是调试器:
[JSON]
-request
module: "test"
method: "test"
parameters:"System.Collections.Generic.Dictionary`2[System.String,System.String]"
RestSharp是谁创造的? ? 发送数组选项对象?
$postData = array(
'key' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'viewType' => 'json',
'module' => 'test',
'method' => 'test',
[options] => stdClass Object
(
[name] => 'ADIDAS'
)
);
我在文档中找到了这个:
要将对象的所有属性添加为参数,请使用AddObject()。 要添加要上传的文件,请使用AddFile()(请求将以多部分编码形式发送)。 要包含请求正文(如XML或JSON),请使用AddBody();。
所以,因为你使用的restRequest.AddObject()
,RestSharp使用的值t.parameters.ToString()
而不是序列化到JSON。
修复:改用restRequest.AddBody(t)
。 您还必须指定内容类型。
request.RequestFormat = DataFormat.Json;
request.AddBody(t);
RestClient restClient = new RestClient("https:");
RestRequest restRequest = new RestRequest(Method.POST);
Test t = new Test();
t.key = ac.Password;
t.viewType = "json";
t.module = "hello";
t.method = "hello";
t.parameters = new Dictionary<string,string>();
t.parameters.Add("wddwdw", "ddd");
restRequest.AddObject(t);
IRestResponse response = restClient.Execute<Test>(restRequest);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.