Solve the Trouble with a cURL request in PHP

| No Comments | No TrackBacks

I have a HTTP status check online tool here. It is made by PHP with cURL extension.

The trouble is some responses are good. Someone tell me that the url should be 302 redir or 200 Ok, but the tool shows 403 Forbidden.

After doing some search and study, I find the problem of some server that don't accept the Header request only.

Anytime you set the option...

PHP Code:

curl_setopt($ch, CURLOPT_NOBODY, true);


CURLOPT_NOBODY automatically shifts the request to a HEAD, type request, so most servers don't allow HEAD type requests, results most times in 403 errors, so you use...

PHP Code:

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');


So cURL, will send the request as GET or POST, but still only really make a HEAD request because the CURLOPT_NOBODY flag was set to true, which causes cURL to read only up to the end of the response header.

The solution found here.


Related Articles

No TrackBacks

TrackBack URL: http://www.yinfor.com/mtcgi/mt-t-0912.cgi/2076

Leave a comment

About this Entry

This page contains a single entry by David Yin published on February 14, 2008 2:36 PM.

basic of basic was the previous entry in this blog.

$() Factory Function, CSS Selectors, XPath Selectors, Custom Selectors is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.21-en

Online Tools