我正在使用restsharp。试图发送2个参数1-yoksis_birim_id(int)
2-qualification :(字符串[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中主体的示例:
$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');
答案 0 :(得分:0)
我以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;
}
答案 1 :(得分:0)
这应该对您有用,您可以通过以下方式将多个参数传递给请求正文:
numberOfSections