简体   繁体   中英

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. 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:

$data = array('postdata' => 'postdata', 'postdata1' => 'postdata1');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM