PHP cURL odd behaviour
I'm trying to parse a page for which I've to first log into that site with a username and password. So I started with a php cURL script to log into the page by using GET method, but problem is that I'm receiving a timeout error everytime, however long timeout period I set.
Login Page: http://myaccount.comeconnect.com/jsp/Login.jsp
URL used in cURL: http://myaccount.comeconnect.com/servlet/MyAccountLogin?loginMode=2&username=user&password=pass&QuickNavigation=Disabled
with valid, user and pass values.
Now when I use this URL in browser, I get logged in easily. So I'm little confused as to why I'm getting timeout errors.
PHP code is not on the same server.
PHP Code:
//create array of data to be posted $post_data['loginMode'] = '2'; $post_data['username'] = $_GET['user']; $post_data['password'] = $_GET['pass']; $post_data['QuickNavigation'] = "Disabled"; //traverse array and prepare data for posting (key1=value1) foreach ( $post_data as $key => $value) { $post_items[] = $key . '=' . $value; } //create the final string to be posted using implode() $post_string = implode ('&', $post_items);
$user = $_GET['user'];
$pass = $_GET['pass'];
//create array of data to be posted
$post_data 开发者_如何转开发= array( 'loginMode' => '2',
'username' => $user,
'password' => $pass,
'QuickNavigation' => "Disabled");
//create the final string to be posted using implode()
$post_string = http_build_query($post_data, '', '&');
//Params for cURL
$ckfile = './cookie.txt';
$url = 'http://myaccount.comeconnect.com/servlet/MyAccountLogin?'.$post_string;
$timeout=10;
$userAgent= "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1";
//create cURL connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT,$timeout);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
$result = curl_exec($ch);
print_r(curl_getinfo($ch));
echo curl_errno($ch) . '-' .curl_error($ch);
curl_close($ch);
echo $result;
The host myaccount.comeconnect.com
appears to be preventing connections from non-customers. You're most likely receiving the error because you're not on an IP address that is allowed to connect and unfortunately, there is no way to fix that.
精彩评论