MaL*_*_eS 5 c# parameters https json http-post
我在这里问过如何制作https帖子,现在工作正常.现在的问题是如何发送参数,名称查询,这是一个json字符串:
{"key1":"value1","key2":{"key21":"val21"}}
我正在做什么和不行的是:
HttpWebRequest q = (HttpWebRequest)WebRequest.Create(Host + ":" + Port);
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
q.Method = "POST";
q.ContentType = "application/json";
q.Headers.Add("JSON-Signature", GetFirma(query));
q.Credentials = new NetworkCredential(user,pass);
byte[] buffer = Encoding.UTF8.GetBytes("query=" + query);
q.ContentLength = buffer.Length;
using (Stream stream = q.GetRequestStream())
{
stream.Write(buffer, 0, buffer.Length);
}
Run Code Online (Sandbox Code Playgroud)
但服务器总是回答说没有'查询'参数.有帮助吗?
提前致谢!
我会用WebClient.UploadValues:
using (WebClient client = new WebClient())
{
NameValueCollection fields = new NameValueCollection();
fields.Add("query", query);
byte[] respBytes = client.UploadValues(url, fields);
string resp = client.Encoding.GetString(respBytes);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11404 次 |
| 最近记录: |