PHP CURL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shanecody
Forum Newbie
Posts: 23
Joined: Fri May 08, 2009 4:12 pm

PHP CURL

Post by shanecody »

This is the first time i have worked with curl.

I have written the below code to access a program using REST, and am getting the error "couldn't connect to host".

Can someone look at it and see if it is something wrong with the code.

Code: Select all

 
<?php
function sendRequest($url, $user, $pass)
{   
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_PORT, 10090);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    
    // grab URL and pass it to the browser
    curl_exec($ch);
    echo curl_error($ch);
    
    // close cURL resource, and free up system resources
    curl_close($ch);
 
}
 
$urlRegions = "http://76.76.241.110:10090/rexwapi/common/regions";
$user = "rex-rex";
$pass = "rex-4-rex";
 
sendRequest($urlRegions, $user, $pass);
?>
 
Last edited by Benjamin on Fri May 08, 2009 4:23 pm, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP CURL

Post by requinix »

Works for me.

Can you ping 76.76.241.110 from your server?
shanecody
Forum Newbie
Posts: 23
Joined: Fri May 08, 2009 4:12 pm

Re: PHP CURL

Post by shanecody »

no i cannot
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP CURL

Post by requinix »

Oh, seems to be blocking pings.

Try telnetting to it on that port.

Code: Select all

$ telnet 76.76.241.110 10090
If you don't get an error message then it probably worked.
shanecody
Forum Newbie
Posts: 23
Joined: Fri May 08, 2009 4:12 pm

Re: PHP CURL

Post by shanecody »

Thank you, it was the server firewall blocking the request out.
Post Reply