5

ここで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);                    
}

しかし、サーバーは常に「クエリ」パラメータがないと答えます。何か助けはありますか?

4

1 に答える 1

9

私は使用します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);
        }
于 2009-10-08T11:22:57.457 に答える