我正在使用restsharp。正在尝试发送2个参数,1-yoksis_birim_id (int)
2-资格:(string json)。但是当我尝试的时候,我得到第一个参数是空的响应。这些是我的代码;enter code here
string styleCreateUrl = "http://xxxx/service/qualificationcreate";
var client = new RestClient(styleCreateUrl);
request.AddHeader("Postman-Token", "xxxx");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("Authorization", string.Format("Bearer " + token), ParameterType.HttpHeader);
request.AddParameter("yoksis_birim_id", bolumid, ParameterType.RequestBody);
request.AddParameter("qualification", bolum, ParameterType.RequestBody);
这是php中的body示例:
$request->setBody('------WebKitFormBoundary7MA4
Content-Disposition: form-data; name="yoksis_birim_id"
xxxx
------WebKitFormBoundary7MA4
Content-Disposition: form-data; name="qualification"
{"belge_type":"","thematic_code":[],"language":{"tr_TR":{"title":"","nonpreferredterms":"","description":"","further_info":"","further_source":"","url":"","eqflevel":"","nqflevel":"","informationlang":"","sourceofinformation":"","sup_lang":"","sup_url":"","nationaloccupation":"","relation":""},"en_US":{"title":"","nonpreferredterms":"","description":"","further_info":"","further_source":"","url":"","eqflevel":"","nqflevel":"","informationlang":"","sourceofinformation":"","sup_lang":"","sup_url":"","nationaloccupation":"","relation":""}}}
------WebKitFormBoundary7MA4Y');
发布于 2019-04-03 00:04:04
这应该适用于您,您可以通过以下方式向请求体传递多个参数:
request.AddParameter("application/x-www-form-urlencoded", $"yoksis_birim_id={bolumid}&qualification={bolum}", ParameterType.RequestBody);
发布于 2019-04-02 21:03:33
我以JSON的形式发送参数,并传入一个对象类类型,以便将数据转换为字符串。
protected static IRestResponse SendRequest<T>(string baseUrl, string requestUrl, T data)
{
var restClient = new RestClient(baseUrl);
var request = new RestRequest(requestUrl, Method.POST);
request.RequestFormat = DataFormat.Json;
var json = Newtonsoft.Json.JsonConvert.SerializeObject(data);
request.AddParameter("application/json", json, ParameterType.RequestBody); // <-- Here
var result = restClient.Execute(request);
return result;
}
public static IRestResponse SendEmail()
{
// Call The Function
var result = SendRequest(baseUrl, urlPageToHit, emailReceiptDto);
return result;
}
https://stackoverflow.com/questions/55475391
复制相似问题