HttpRequest passing POST parameters?
Monkey Forums/Monkey Programming/HttpRequest passing POST parameters?
| ||
it's pretty obvious that GET call can use something like these:get_req = New HttpRequest("GET", "http://www.domain.com/index.php?a=1&b=2", Self) But what about POST requests? Any way to add parameters 'a=1' and 'b=2'? UPDATE: this works --> |
| ||
If you change "GET" to "POST" it should just work 'as is' - and dont' forget to use Send( data:String ) instead of Send() to send the request data. |
| ||
I noticed that the example has "hello world" as the data string, how do I catch this in the server side php? I tried print_r($_POST) which showed empty stuff. I'll give it another go, but to me it didn't seem to work as is.. |
| ||
Here's my monkey/android code:post_req = New HttpRequest("POST", "http://www.site.com/index.php?a=3&b=4", Self) post_req.Send("a=Hello World!&b=2") And here's the server side php: And here's the output: As you can see, all the POST variables are empty. ...but the $_GET["a"] works just fine. So... back to clarify my orignal question: how do I can send POST variables? |
| ||
Ok, you apparently need to set variables in the post body... http://stackoverflow.com/questions/14551194/how-are-parameters-sent-in-an-http-post-request When you do the send, you'll also have to use "application/x-www-form-urlencoded" for the mimeType parameter. |
| ||
Ok. Will try it out. What the "data" does / can be used? |
| ||
Yeh... now it works. So basically I now have this code: And I received the response properly: So all good. Thanks! |
| ||
POST variables are empty. i get this too , bu in my PHP Method OnCreate() ' SetUpdateRate 1000 Local myURL:String = "yourURL.php" ' after the ? in the uri you can have vars get_req = New HttpRequest("GET", myURL + "?user=Monkey_8_GET&pass=getOne", Self) get_req.Send ' localhost:80/testcont/ post_req = New HttpRequest("POST", myURL + "?user=Monkey_8_POST&pass=postOne", Self) 'need : enctype="multipart/form-data" 'post_req.SetHeader("enctype", "text/plain") ' but this shows in $rawdata = file_get_contents('php://input'); php side post_req.Send "some,big,CSV,string,that,could,have,162763663763,all,the,telemetry,needed" End <?php // $rawdata = file_get_contents('php://input'); echo "This is the content: " . $rawdata ." :". PHP_EOL . "<BR>" ; $flatFile = 'dope.txt' ; if( file_exists($flatFile)){ $valToAdd = file_get_contents($flatFile); $valToAdd .= $user . " : " . $pass . PHP_EOL . $rawdata . PHP_EOL ;// curPageURL() ."\n" ; file_put_contents( $flatFile , $valToAdd , LOCK_EX ); echo PHP_EOL ; } ?> |