[英]How can I make a CURL request to IP Address PHP?
I am trying to make a CURL request to an IP address, however it just fails and I have no idea why.我正在尝试向 IP 地址发出 CURL 请求,但是它失败了,我不知道为什么。 This is my code:这是我的代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"127.0.0.1/script.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "postdata=postdata&postdata1=postdata1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close ($ch);
However it justs returns an empty result.但是它只是返回一个空结果。 Any suggestions here?这里有什么建议吗?
Try with:尝试:
curl_setopt($ch, CURLOPT_URL,"http://127.0.0.1/script.php");
and CURLOPT_POSTFIELDS sould be an array:和 CURLOPT_POSTFIELDS 应该是一个数组:
$data = array('postdata' => 'postdata', 'postdata1' => 'postdata1');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.