views:

723

answers:

1

I have asked here how to make the https post, and now that works fine. Problem now is How to send a parameter, name query, wich is a json string:

{"key1":"value1", "key2":{"key21":"val21"} }

What I'm doing and doesn't work is:

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

But the server always answer saying there's no 'query' parameter. Any help?

Thanks in advance!

+4  A: 

I would use WebClient.UploadValues:

        using (WebClient client = new WebClient())
        {
            NameValueCollection fields = new NameValueCollection();
            fields.Add("query", query);
            client.UploadValues(url, fields);
            byte[] respBytes = client.UploadValues(url, fields);
            string resp = client.Encoding.GetString(respBytes);
        }
Marc Gravell
Thanks Mark, but I'm just getting the same answer as with my code. I'll try asking server developers again for more feed back.
MaLKaV_eS
Well, I have tried it locally and works great, so must be some compatibility issues or something similar.
MaLKaV_eS