简体   繁体   中英

PHP Curl does not send POST request to server

I have this code:

<?php
$data = array('name' => 'Ross', 'php_master' => true);

$url = 'http://dsaasd.adsds.nl:8081/cops.nsf/orders?openagent';


$html_brand = "www.google.com";
$ch = curl_init();

$options = array(
    CURLOPT_URL            => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER         => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_ENCODING       => "",
    CURLOPT_AUTOREFERER    => true,
    CURLOPT_CONNECTTIMEOUT => 120,
    CURLOPT_TIMEOUT        => 120,
    CURLOPT_MAXREDIRS      => 10,
     CURLOPT_VERBOSE => true,
);
curl_setopt_array( $ch, $options );
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ( $httpCode != 200 ){
    echo "Return code is {$httpCode} \n"
        .curl_error($ch);
} else {
    echo "<pre>".htmlspecialchars($response)."</pre>";
}

curl_close($ch);

 ?>

The problem is, if i send curl post to: $url = ' http://dsaasd.adsds.nl:8081/cops.nsf/orders?openagent ';

Then it does NOT work.

But if i send curl post to the same service but on a different server then it works, this is the other server $url = ' http://dsaasd.adsds.nl:80/cops.nsf/orders?openagent ';

I also post data by normal form post to: $url = ' http://dsaasd.adsds.nl:8081/cops.nsf/orders?openagent '; And then it works and i receive data on the server.

But with this curl post i keep getting: Return code is 0 Failed to connect to 11.43.45.123: Network is unreachable

Anyone have any idea?

I think you need to add CURLOPT_POST to the $options array. Docs here .

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