我試圖發送請求並從MailChimp API獲取響應。 。到目前爲止,GET,POST和DELETE工作正常,但是,PATCH總是導致錯誤的請求,您可以識別此代碼中的錯誤?REST API PATCH請求
string data = "{\"name\": \"TestListTWOTWOTWO\"}";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Headers[HttpRequestHeader.Authorization] = accessToken;
request.Method = "PATCH";
request.ContentType = "text/plain;charset=utf-8";
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
byte[] bytes = encoding.GetBytes(data);
request.ContentLength = bytes.Length;
using (Stream requestStream = request.GetRequestStream())
{
// Send the data.
requestStream.Write(bytes, 0, bytes.Length);
}
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
與request.GetResponse()行上的錯誤occus行; 是未處理引發WebException說遠程服務器返回錯誤:檢查錯誤響應後(400)錯誤的請求
,這裏是什麼它說
"Your request doesn't appear to be valid JSON:
\nParse error on line 1:\nPATCH /3.0/lists/9bb\n^\n
Expected one of: 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['"
最好附上錯誤信息。 – Opal