开发者

Has anyone experienced curl request inconsistencies?

I'm trying to request a url but it fails and when I var dump the result of curl exec it returns false.

http://mydomain.com:8807开发者_C百科/getstate/?zipcode=22311&field=statecode

In the browser I can access it and it returns the correct HTTP Content Body, Content Type is text/html.

If I change it to:

http://mydomain.com:8807/getstate/?zipcode=22311&field=state

Which is the same REST service except the parameter value is different, my curl stuff works fine. How could this be?

I'm not making multiple requests, I'm only doing one instance..

$url = 'http://mydomain.com:8807/getstate/?zipcode=22311&field=state';

Which is the same REST service except the parameter value is different, my curl stuff works fine. How could this be?

$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
$request = curl_exec( $ch );
var_dump($request);

I'm pretty damn positive it's not a typo, can't think of a reason. It returns bool(false) for the statecode but returns the right thing for state.

Update: Seems like the response headers are not proper - the browser is lenient and renders the page regardless of incorrect headers ( or lack thereof ).


You are missing something. Turn on curl debugging to tell you more curl_setopt($ch, CURLOPT_VERBOSE, true); Also see what gets returned in firebug, and use fiddler to help debug.


Try to set the same user agent of a browser in Curl before making the request...

if it works with the browser it should work in this way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜