您好我想将每个HTTP请求的3个变量发送到另一个站点,并希望得到响应。 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
?>
答案 0 :(得分:0)
试试这个:
$url = "http://www.testpage.com/api.php";
$r = new HTTPRequest($url, HTTP_METH_POST);
$r->addPostFields(array('authcode' => $apikey, 'var1' => '', 'var2' => ''));
$r->send();
将数组中的空字段替换为var1和var2的值。
此外,您可能希望使用cURL而不是内置HTTP处理程序。 PHP + curl, HTTP POST sample code?