cURL / Mailing Lists / curl-users / Single Mail

curl-users

405 error using curl/php

From: <bve_at_telusplanet.net>
Date: Wed, 19 Jul 2006 15:08:59 -0700

This is a first post to the list for me, so hi all.

I am running into an issue with php curl while attempting to post to a remote
server. I have tried finding a solution in the archives without any luck.

Below is the script (with some comments) which ends up producing a 405 on the
post. This is based off of a script I found which was I think in the examples
here (ebay_login.php) by Imran Khalid imranlink_at_hotmail.com in 2004

I have used the 'liveHTTPHeaders' plugin for Firefox to ensure I have the proper
form info being posted.

I would be very grateful for any support as I am new to using curl, and I seem
to be running in circles on this one.

//============================================================================
        $user_id = "user"; // Please set your user ID
        $user_password = "password"; // Please set your Password
        $cookie_file_path = "/home/burke/public_html/curl/data/srm_snack.txt"; //
Cookie File path

        $LOGINURL = "http://srm.tsl.telus.com/";
        $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4)
Gecko/20030624 Netscape/7.1 (ax)";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$LOGINURL);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
    $result = curl_exec ($ch);
    curl_close ($ch);
// print $result; // if I enable output here I get the form as expected, as
well the cookie has been written

// 2- Post Login Data to Page http://signin.ebay.com/aw-cgi/eBayISAPI.dll

        $LOGINURL = "http://srm.tsl.telus.com/";
        $POSTFIELDS = 'upw='. $user_password
.'&wanturl=%2Fsrm%2Freports&user='.$user_id.'&pass='. $user_password.'&system=srm';
    $reffer = "http://srm.tsl.telus.com/index.cfm";

        $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$LOGINURL);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_REFERER, $reffer);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
    $result = curl_exec ($ch);
    curl_close ($ch);
    print $result; // this outputs an IIS 405 error as below

------------------------------------
The page cannot be displayed
The page you are looking for cannot be displayed because the page address is
incorrect.

Please try the following:

    * If you typed the page address in the Address bar, check that it is entered
correctly.
    * Open the 142.178.219.225 home page and then look for links to the
information you want.

HTTP 405 - Resource not allowed
Internet Information Services

Technical Information (for support personnel)

    * More information:
      Microsoft Support
-------------------------------------------
Received on 2006-07-20