CURL Post data to ASP page

Discussion in 'PHP' started by goodmast3r, Feb 20, 2011.

  1. #1
    I have a curl code to past POST data. This code is working if the form is submited to PHP file. But if the code is submited to ASP file, it isn't working. It is as if ASP file does not recognize my POST data.

    The code I use is simple CURL code:

    try {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);

    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $response = curl_exec($ch);
    echo $response;
    } catch (Exception $e) {
    echo 'Caught exception: ', $e->getMessage(), "\n";
    }
     
    goodmast3r, Feb 20, 2011 IP
  2. mallorcahp

    mallorcahp Peon

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have you tried posting the data via an ajax call and seeing if that works? If it works for the php file, sounds to me like the problem is with the asp handling it ...
     
    mallorcahp, Feb 21, 2011 IP
  3. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #3
    You might need to add a referral option:

    
    curl_setopt($ch,CURLOPT_REFERER, $url);
    
    PHP:
    Also you can always check the error by doing:

    
    $errorMessage = curl_errno($ch);
    $errorNumber = curl_error($ch);
    
    PHP:
     
    ThePHPMaster, Feb 21, 2011 IP
  4. goodmast3r

    goodmast3r Active Member

    Messages:
    1,220
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    78
    #4
    Thanks guys. I'll try it
     
    goodmast3r, Feb 21, 2011 IP