1

Hi i want to send 3 Variables per HTTP Request to another Site and want get the Response. check.php:

<html><body> 

  <form action="response.php" method="post">
   <p>Variable1: <input type="text" name="var1" /></p>
   <p>Vairable2: <input type="text" name="var2" /></p>
   <p><input type="submit" /></p>
  </form>
</body></html>

response.php:

<?php 

 $url = "http://www.testpage/api.php?authcode=";

 $apikey = "xxxxxxx" ;

 $request = new HTTPRequest($url$apikey&$var1&$var2, HTTP_METH_POST); //req not work !
 $request->send();                                                    //nothing happens
 response = $request->getResponseBody();                              //only
                                                                      //got
 echo "$response ";                                                   //500 error

?>
dA_uNknOwN
  • 711
  • 1
  • 13
  • 23

1 Answers1

0

Try this:

$url = "http://www.testpage.com/api.php";
$r = new HTTPRequest($url, HTTP_METH_POST);
$r->addPostFields(array('authcode' => $apikey, 'var1' => '', 'var2' => ''));
$r->send();

Replace empty fields in array with your values for var1 and var2.

Also, you may want to use cURL rather than built-in HTTP handler. PHP + curl, HTTP POST sample code?

Community
  • 1
  • 1
if __name__ is None
  • 9,863
  • 15
  • 48
  • 68