homepage Welcome to WebmasterWorld Guest from 54.163.72.86
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
CURL : [error] Not Acceptable
CURL : [error] Not Acceptable
camilord




msg:3842354
 7:03 pm on Feb 4, 2009 (gmt 0)

i tried to CURL http://www.example.com/wb/wxfcst.html and the codes below... but i'm having problem, i can't get through...

anybody have a tricks to bypass the error? please help.. thanks..

<?php
// Create a curl handle to a non-existing location
$ch = curl_init('http://www.example.com/wb/wxfcst.html');

// Execute
curl_exec($ch);

// Check if any error occured
if(!curl_errno($ch))
{
$info = curl_getinfo($ch);

echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
}

// Close handle
curl_close($ch);
?>

[edited by: coopster at 8:32 pm (utc) on Feb. 4, 2009]
[edit reason] please use example.com, thanks! [/edit]

 

camilord




msg:3842377
 7:23 pm on Feb 4, 2009 (gmt 0)

I'm about to give up.. thanks God.. it's solved... :)

<?php

$userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';

// Create a curl handle to a non-existing location
$ch = curl_init('http://www.example.com/wb/wxfcst.html');

// add useragent
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);

// Execute
curl_exec($ch);

// Check if any error occured
if(!curl_errno($ch))
{
$info = curl_getinfo($ch);

echo '<hr>Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
}

// Close handle
curl_close($ch);

?>

[edited by: coopster at 8:33 pm (utc) on Feb. 4, 2009]
[edit reason] please use example.com in code [/edit]

coopster




msg:3842442
 8:34 pm on Feb 4, 2009 (gmt 0)

Yes, there may be certain options you need to set before executing the request with curl. Glad you got it sorted.

caribguy




msg:3842465
 9:07 pm on Feb 4, 2009 (gmt 0)

If you want to prevent the hammering of a third party service, you should try to cache a local copy of the information. Your visitors can then use the local copy instead.

An easy way to do this is by setting a crontab entry:

# Some service - info request XML (every 4 hours at :36)
36 */4 * * * /usr/local/bin/wget -q http://www.example.com/auto/rss_full/global/stations/12345.xml -O /usr/local/www/folder/file.xml &

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved