user757059
user757059

Reputation: 1

error with CURL post

using CURL getting this kind of error.. error text:"The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access".....

The URL being used:http://mkash.something.com

My CURL code: $server = parse_url($url);

    if (!isset($server['port'])) {
        $server['port'] = ($server['scheme'] == 'https') ? 443 : 80;
    }

    if (!isset($server['path'])) {
        $server['path'] = '/';
    }

    if (isset($server['user']) && isset($server['pass'])) {
        $header[] = 'Authorization: Basic ' . base64_encode($server['user'] . ':' . $server['pass']);
    }
    print_r($server);die;
    if (function_exists('curl_init')) {
        $curl = curl_init($server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : ''));
        curl_setopt($curl, CURLOPT_URL, $Url);
        curl_setopt($curl, CURLOPT_PORT, $server['port']);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
        curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);

        $result = curl_exec($curl);

        curl_close($curl);
    } else {
        exec(escapeshellarg(MODULE_PAYMENT_TEST_PAYPAL_EXPRESS_CURL) . ' -d ' . escapeshellarg($parameters) . ' "' . $server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : '') . '" -P ' . $server['port'] . ' -k', $result);
        $result = implode("\n", $result);
    }

    return $result;

PS:i am running this on my localhost(WAMP). Any suggestions?

Upvotes: 0

Views: 1235

Answers (2)

Jorgesys
Jorgesys

Reputation: 126485

I had this issue using IIS, I was using a static html page as a landing page, by default the web server doesn't allow POST or GET verb on .html page, I had to change my page into .asp (.php or .aspx will work too).

enter image description here

Upvotes: 0

mattmanser
mattmanser

Reputation: 5796

That function does a POST you'll probably need to do a GET. Try adding -G to the exec line like this:

        exec(escapeshellarg(MODULE_PAYMENT_TEST_PAYPAL_EXPRESS_CURL) . ' -d ' . escapeshellarg($parameters) . ' "' . $server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : '') . '" -P ' . $server['port'] . ' -k -G', $result);

That might not work as you've not given enough information about the end point you're using, look at the API, does it say what it expects? It could be moaning that you're not doing a PUT or DELETE, in which case you need to use -X.

To be honest, I would try to get the curl request working without the function first, echo out the curl command so you can play with it directly.

Upvotes: 1

Related Questions