How do you send a patch request from a c# client?

妖精的绣舞 提交于 2019-12-06 15:01:55

You are missing the METHOD in your call to UploadString.

string reply = client.UploadString(url, "keepForever = true");

should be:

string reply = client.UploadString(url, "PATCH", "keepForever = true");

A 401 is unauthorised, so also see if there is a step before in your Powershell where you are logging in or joining a session, you would need to replicate that in your C#.

In order to send a PATCH request you can use WebClient.UploadData.

string data = "keepForever = true";
WebClient client = new WebClient();
client.Encoding = System.Text.Encoding.UTF8;
string reply = client.UploadData(url, "PATCH", System.Text.Encoding.UTF8.GetBytes(data));
Console.WriteLine(reply);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!