954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

curl not working for getting a web page content, why?

Hi all
i am using a curl script to go to a link and get its content for further manipulation. following is the link and curl script:

<?php 
$url = 'http://criminaljustice.state.ny.us/cgi/internet/nsor/fortecgi?serviceName=WebNSOR&amp;templateName=detail.htm&amp;requestingHandler=WebNSORDetailHandler&amp;ID=368343543';

//curl script to get content of given url
	$ch = curl_init();
// set the target url
	curl_setopt($ch, CURLOPT_URL,$url);
// request as if Firefox
	curl_setopt($ch, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); 
	curl_setopt($ch, CURLOPT_NOBODY, false);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$result= curl_exec ($ch);
	curl_close ($ch);
	echo $result;
?>


but the website is not excepting it through script it is giving user exception in result, but if we normally paste the url in browser it is opening the page perfectly alright.

Please help, what i am doing wrong here.

Thanks and regards
jyotiu

jyotiu
Light Poster
33 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

I got what the problem was in the url there is & instead of & symbol that is creating a problem

jyotiu
Light Poster
33 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

i also have same issue plz help me to send email me: [snipped]

Muhammad Sohail Qureshi
PHP Web Developer

sohail_mubeen
Newbie Poster
3 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

to after execute url paste this code
print_r(curl_getinfo($ch));
use exit();function now check what show in array.
Thanks.

sohail_mubeen
Newbie Poster
3 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

After few hours of hard work i find a way to solve my problem. i install WAMP5 Version 1.4.3 change php.ini file the code from ;extension=php_curl.dll to extension=php_curl.dll this thing solve my problem.

code that i use:

<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://news.google.com/news?hl=en&topic=t&output=rss");
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
?>
sohail_mubeen
Newbie Poster
3 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You