c# - Display response from the web server in pop up window -


this question has answer here:

i have windows form submits post request web server. return url.

something when curl web server:

curl -d 'info={ "employeeid": [ "1234567", "7654321" ], "salary": true, "bonuspercentage": 10}' http://example.com/xyz/php/api/createjob.php 

url returned:

http://example.com/xyz#newjobapi:id=19 

now replicate above process on windows form when user clicks button, post required information windows form server.

but dont response upon clicking button. shows empty messagebox.

kindly let me how display url returned server user pop window. thanks.

my c# code:

private void button8_click(object sender, eventargs e) {     httpwebrequest webrequest;     string requestparams = "\'info={ \"employeeid\": [ \"1234567\", \"7654321\" ], \"salary\": true, \"bonuspercentage\": 10}\'";      byte[] bytearray = encoding.utf8.getbytes(requestparams);       webrequest = (httpwebrequest)webrequest.create("http://example.com/xyz/php/api/createjob.php");      webrequest.method = "post";     webrequest.contenttype = "application/json";                 webrequest.contentlength = bytearray.length;      using (stream requeststream = webrequest.getrequeststream())     {         requeststream.write(bytearray, 0, bytearray.length);     }      // response.     using (webresponse response = webrequest.getresponse())     {         using (stream responsestream = response.getresponsestream())         {             streamreader rdr = new streamreader(responsestream, encoding.utf8);             string json = rdr.readtoend(); // response server             messagebox.show("url returned: " + json);          }     } } 

if execute this:

curl --trace con -d "info={ 'blah': 10}" http://example.com/xyz/php/api/createjob.php 

this part of output:

00a0: 0d 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 ..content-type: 00b0: 61 70 70 6c 69 63 61 74 69 6f 6e 2f 78 2d 77 77 application/x-ww 00c0: 77 2d 66 6f 72 6d 2d 75 72 6c 65 6e 63 6f 64 65 w-form-urlencode 00d0: 64 0d 0a 0d 0a                                  d.... 

and means this:

webrequest.contenttype = "application/json";  

isn't sending data in way php make sense of it. guess php doing $info = $_post['info'] serverside. expecting form values posted.

instead should send curl sending:

webrequest.contenttype = "application/x-www-form-urlencoded";  

as send form , populate $_post array in php.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -