1
HTTP 400 error using Curl
Post Body
I'm trying to access this API, for a coding interview test (so I've masked the URLs), but I'm getting "HTTP/1.1 400 BAD_REQUEST Content-Length: 0 Connection: Close". I'm using the example URL and the hostname/headers they provided.
What could I be missing in my request that is causing this problem, short of the URL being wrong?
<?php
$url = "api-recruitment-test.com";
$ch = curl_init($url);
$api_headers = array(
'AcceptTenant: uk',
'AcceptLanguage: en-GB',
'Authorization: Basic VGVjaFRlc3RBUEk6dXNlcjI=',
'Host: api-recruitment-test'
);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $api_headers);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2');
$data = curl_exec($ch);
$info = curl_getinfo($ch);
echo '<pre>';
print_r($info);
echo '</pre>';
curl_close($ch);
//test the url connection
if (!$fp = fopen($url, 'r')) {
trigger_error("Unable to open URL ($url)", E_USER_ERROR);
}
$json = file_get_contents($data);
$data = json_decode($json, TRUE);
print_r($data);
$meta = stream_get_meta_data($fp);
echo '<pre>';
var_dump($meta);
echo '</pre>';
fclose($fp);
?>
Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
14,533
Link Karma
10,604
Comment Karma
3,929
Profile updated: 2 days ago
Posts updated: 8 months ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 9 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/AskProgramm...