我需要从控制台应用程序发出补丁请求(无关紧要,但我认为这可以完成工作)
PATCH '{
"Fields": [
{
"fieldType" : "FName",
"value" : "ABC123"
},
{
"fieldType" : "LName",
"value" : "XYZ123",
},
]
}' /api/clients/clientID/Fields/
现在,作为一个故意发送Rainmeter之类的API请求的人,不得不做PATCH请求,老实说我不知道该怎么办。
private string getJsonContent(DataRow _dataRow)
{
string sb = "PATCH '{\n \"Fields\" : [\n { \"fieldType\" : \"FName\",\n\"value\" : \"" + _dataRow[0].ToString() + "\"\n},\n" +
"{ \"FieldType\" : \"LName\",\n\"value\" : \"" + _dataRow[1].ToString() + "\"\n}\n]\n}' /api/clients/clientID/Fields/";
return sb;
}
DataTable dt = new DataTable();
//Populate this DataTable using connection to database
}
Uri MyUri = new Uri("http://www.default.com/");
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(MyUri);
//request.Headers[HttpRequestHeader.Authorization] = accessToken;
request.Method = "PATCH";
request.ContentType = "application/json";
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();
foreach(DataRow dr in dt.Rows)
{
string data = getJsonContent(dr);
//我现在该怎么办?
我能找到的几乎所有内容都是关于POST / PUT / GET的。我似乎无法找到任何完整补丁请求的完整来源/示例。 Youtubing关于这个只给出了PUT / POST / GET的结果,堆栈溢出似乎只有部分关于补丁的例子,RFC文档对我来说真的很难解析我的级别并且谷歌搜索它并没有产生太多。
请帮助..