我使用以下参数发送带有请求正文的 DELETE 请求:
服务器以状态 500 响应。我愿意
curl -D- -X DELETE -d "{\"pin\":\"1111\"}" -H "Content-Type:application/json" -H "Authorization:Basic sameasinimagabove" https://myrestapiendpoint/resource/id
它有效。我使用最新版本的 RestSharp.WindowsPhone v. 104.3.3.0。
有什么问题?构建和发送请求的代码:
RestRequest PrepareRequest(Method method, string url, IDictionary<string, object> data)
{
var request = new RestRequest(url, method);
request.AddHeader("Authorization", "Basic " + "yadyadyadyada");
request.AddHeader("X-Originator-Type", "app");
request.AddHeader("X-Os-Type", Environment.OSVersion.Platform.ToString());
request.AddHeader("X-Os-Version", Environment.OSVersion.Version.ToString());
request.AddHeader("X-Device-Id", AppUtil.DeviceId);
request.AddHeader("X-Client-Version", AppUtil.ApplicationVersion);
request.AddHeader("Locale", System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName);
request.AddHeader("If-Modified-Since", DateTime.UtcNow.ToString("u"));
if (data != null || method == Method.PUT || method == Method.POST || method == Method.DELETE)
{
request.RequestFormat = DataFormat.Json;
if (data == null)
data = new Dictionary<string, object>();
string json = JsonParser.Serialize(data);
request.AddParameter("application/json", json, ParameterType.RequestBody);
}
}
_restClient.ExecuteAsync(request, response =>
{
_activeRequests.Remove(handle);
done(responseHandler(AddRequestToResponse(request, response)));
});