views:

49

answers:

1

I need to reach a webservice which respondss to the postvar "data". How do i set this name in c# with a httprequest... this is what i got:

            UTF8Encoding encoding = new UTF8Encoding();
            byte[] data = encoding.GetBytes(postData); 

            HttpWebRequest myRequest =
              (HttpWebRequest)WebRequest.Create("http://secreturl/jubidubb.php");
            myRequest.Method = "POST";
            myRequest.ContentType = "application/x-www-form-urlencoded";
            myRequest.ContentLength = data.Length;
            myRequest.KeepAlive = true;
            Stream newStream = myRequest.GetRequestStream();


            newStream.Write(data, 0, data.Length);
            newStream.Close();

            // The response
            WebResponse response = myRequest.GetResponse();
+2  A: 

Doesn't responds to the postvar "data" simply mean that your postData string needs to be of the form "data=mydata"?

RichieHindle
How to do this, while rest of the data is jsonencoded?
Without knowing more about the spec of the service you're using, it's impossible to say, but I'd guess your `postData` string needs to be of the form `data=my-json-encoded-data`...?
RichieHindle
what i got in data now is : {"name":"rox", "age":"20"}
all i need to do is to give it a postname :P
Then try `data={"name":"rox", "age":"20"}`
RichieHindle
Thank you. Will try it out tomorrow :)
It worked :)Thank you!