Jump to content

problems with cURL


caedo

Recommended Posts

Hi

 

I'm using cURL to connect to Yahoo Contact Book Service, I espect a XML file  to be return, but the only thing I get is this message:

 

Your call to Yahoo Web Services returned an unexpected HTTP status of:238

 

The strange thing is that each time a refresh the page I get a new error number that goes from 202 to 256.

Here's the code, to see if you can spot the problem.

 

 


                        $cookie = $this->auth_cookie;
		$appid = APPID;
		$wssid = $this->wssid;
		$url =  "http://address.yahooapis.com/v1/searchContacts";
		$url .= "?format=xml&fields=name";
		$url .= "&appid=$appid&WSSID=$wssid";
		$ch = curl_init();
		curl_setopt( $ch, CURLOPT_URL, $url );
		//curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie ); 
		curl_setopt( $ch, CURLOPT_HTTPHEADER, array("Cookie: $cookie"));
		curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
		$response = curl_exec( $ch );
		curl_close($ch);
		$status_code = array();
		preg_match('/\d\d\d/', $response, $status_code);
		//echo phpinfo();
		// Check the HTTP Status code
		switch( $status_code[0] ) {
			case 200:
				// Success
				break;
			case 503:
				die('Your call to Yahoo Web Services failed and returned an HTTP status of 503. That means: Service unavailable. An internal problem prevented us from returning data to you.');
				break;
			case 403:
				die('Your call to Yahoo Web Services failed and returned an HTTP status of 403. That means: Forbidden. You do not have permission to access this resource, or are over your rate limit.');
				break;
			case 400:
				// You may want to fall through here and read the specific XML error
				die('Your call to Yahoo Web Services failed and returned an HTTP status of 400. That means:  Bad request. The parameters passed to the service did not match as expected. The exact error is returned in the XML response.');
				break;
			default:
				die('Your call to Yahoo Web Services returned an unexpected HTTP status of:' . $status_code[0]);
		}
		// Get the XML from the response, bypassing the header
		if (!($xml = strstr($response, '<?xml'))) {
			$xml = null;
		}

		// Output the XML
		echo htmlspecialchars($xml, ENT_QUOTES);

 

 

I hope you can help me, thanks

 

Caedo.

Link to comment
https://forums.phpfreaks.com/topic/109637-problems-with-curl/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.