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, "$loginUsername:$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> </p>";
var_dump($headers);
curl_close($ch);
Thanks
James