c#代码通过WebService传递json数据

本文关键字:传递 json 数据 WebService 代码 | 更新日期: 2023-09-27 18:12:40

response = requests.patch( "https://<manageraddress>/api/admin/configuration/v1/conference/1/", auth=('<user1>', '<password1>'), verify=False, data=json.dumps({'pin': '1234'}) https://tsmgr.tsecurevideo.com/api/admin/configuration/v1/conference/1/" 

我试过了

  HttpWebRequest httpWReq =(HttpWebRequest)WebRequest.Create(string.Format("https://tsmgr.tsecurevideo.com/api/admin/configuration/v1/conference/2/"));
   Encoding encoding = new UTF8Encoding();
   string postData = "{'"pin'":'"1234'"}";
   byte[] data = encoding.GetBytes(postData);
   httpWReq.ProtocolVersion = HttpVersion.Version11;
   httpWReq.Method = "POST";
   httpWReq.ContentType = "application/json";//charset=UTF-8";
   string credentials =   Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes("admin" + ":" + "password"));
   httpWReq.Headers.Add("Authorization", "Basic " + credentials);
   httpWReq.ContentLength = data.Length;

   Stream stream = httpWReq.GetRequestStream();
   stream.Write(data, 0, data.Length);
   stream.Close();
   HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
   string s = response.ToString();
   StreamReader reader = new StreamReader(response.GetResponseStream());

我得到错误

远程服务器返回错误:(501)Not Implemented.

c#代码通过WebService传递json数据

尝试以这种方式发送凭据

string auth = string.Format("{0}:{1}", "admin","password");
string data = Convert.ToBase64String(Encoding.ASCII.GetBytes(auth));
string credentials= string.Format("{0} {1}", "Basic", data );
httpWReq.Headers[HttpRequestHeader.Authorization] = credentials;

参考这里的编码文档。ASCII

来自HTTP规范

501未实现

服务器不支持完成请求所需的功能。当服务器无法识别请求方法并且无法支持任何资源时,这是适当的响应。

听起来好像服务器不支持PATCH方法