找了好多资料都没有关于put请求的相关文章,自己摸索了下,以下方式可以成功。
public static String SendPutRequest(string baseUrl, string requestUrl, object data)
{
RestClient client = new RestClient(baseUrl);
client.Proxy = _nullProxy;
String responseStr = null;
var request = new RestRequest(requestUrl, Method.PUT);
request.Timeout = _timeOut;
request.RequestFormat = DataFormat.Json;
request.AddObject(data);
RestResponse response = null;
try
{
response = client.Execute(request);
}
catch (Exception e)
{
logger.Error("SendPutRequest error:" + e.StackTrace);
}
if (response == null)
{
return null;
}
responseStr = response.Content;
return responseStr;
}
这里传入的data对象不需要再转为json字符了。