POST或GET请求到达,我的代码对其起作用。但是它应该创建一个新请求,复制第一个(标题,正文/内容),并将其发送到另一个服务器,就像收到它一样。什么是用PHP完成此任务的最快方法?
答案 0 :(得分:1)
这样的东西?
$data = $_REQUEST;
/*
* cURL request
*
* @param $url string The url to post to 'theurlyouneedtosendto.com/m/admin'/something'
* @param $req string Request type. Ex. 'POST', 'GET' or 'PUT'
* @param $data array Array of data to be POSTed
* @return $result Obj HTTP resonse in json decoded object
*/
function curl_req($url, $req, $data='')
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $req);
if (is_array($data)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$result = json_decode($result);
curl_close($ch);
return $result;
}
$result = curl_req("theurlyouneedtosendto.com/path/after/url", "POST", $data);