Mark Adewale
Mark Adewale

Reputation: 35

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?

Upvotes: 2

Views: 975

Answers (1)

dassoun
dassoun

Reputation: 79

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);

Upvotes: 1

Related Questions