开发者

Solution to HEAD request problems

开发者 https://www.devze.com 2022-12-15 05:19 出处:网络
I have been working on a script to post customer data to a dialing server.I posted a similar problem about this a while ago but was finally able to get some responses.However, I am facing another issu

I have been working on a script to post customer data to a dialing server. I posted a similar problem about this a while ago but was finally able to get some responses. However, I am facing another issue.

When I test the script from my localhost server, the data is being sent successfully and I get a 200 OK http response. From my localhost server, when I check the details of the curl_info, the request_header shows that POST has been used.

When I test the same script on another server, no response gets returned. The HTTP_CODE however does show 401 which indicates and authorisation issue. The request_header however is HEAD.

Now can anyone help me figure out why there is such a difference between the request_headers and if there is a way to force the seconds server to use POST instead. As I get the feeling that this server has a problem with HEAD requests.

This the script that I am using:

$full_url = $_GET['url'] . urlencode($_GET['attrib']);

$loginUsername = "123456";
$loginPassword = "123456";

$unencriptedString = $loginUsername.":".$loginPassword;
$encryptedString = base64_encode($unencriptedString);


$headers         =    array("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
                        "Accept-Language: en-gb",
                        "Accept-Encoding: gzip,deflate",
                        "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
                        "Keep-Alive: 300",
                        "Connection: keep-alive",
                        "Content-type: application/x-www-form-urlencoded;charset=UTF-8",
                        "Content-length: " . strlen($_GET['attrib']),
                        "Transfer-Encoding: chunked",
                        $_GET['attrib'],
                        );

$user_agent       = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.5)";                             
$ch = curl_init();
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );    # required for https urls
curl_setopt( $ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt( $ch, CURLOPT_URL, $_GET['url']);
curl_setopt( $ch, CURLOPT_USERPWD, "$log开发者_如何学编程inUsername:$loginPassword"); //login
curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt( $ch, CURLOPT_POST, 1); 
curl_setopt( $ch, CURLOPT_POSTFIELDS, $_GET['attrib']);
curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 
// curl_setopt( $ch, CURLOPT_TIMEOUT, 10);
curl_setopt( $ch, CURLINFO_HEADER_OUT, 1);
curl_setopt( $ch, CURLOPT_VERBOSE, 1);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER,1);

$response = curl_exec($ch);  
if (!$response) {  
   $response = curl_error($ch);  
}
echo "<p>" . $response . "</p>"; 

$info = curl_getinfo($ch);

if (curl_error($ch)) {
   echo "ERROR ". curl_error($ch) ."\n<br/>";
} else {
   print "<pre>";
   print_r($info);
   print "</pre>";
}

echo "<p>&nbsp;</p>";   

var_dump($headers);

curl_close($ch);

Thanks

James


HEAD requests are usually the result of a proxy or cache checking if cached content is still valid before issuing a GET to refresh the content - is there a proxy or cache between the client and server? I wouldn't expect it to be used before a POST because it doesn't make any sense.

I would try and use Wireshark or similar to trace exactly the sequence of requests and responses and where they are originating.

Another altenerative is a simple proxy that dumps the HTTP traffic, first result in Google is this one (not used it myself): http://www.fiddler2.com/fiddler2/


I would try using this option curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

As a workaround you may consider using CURLOPT_CUSTOMREQUEST option.

0

精彩评论

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