I'm not a PHP programmer by trade, but am in a bind having to code a PHP script that will send an HTTP POST request to an API. This post also includes some JSON content (which I've verified is correctly formatted using jsonlint.com). I'm continually getting "400 Bad Request" so I'm assuming I have something formatted incorrectly.
$json = "<JSON markup goes here>";
$options = array(
'http' => array
(
'method' => 'POST',
'content' => $json,
'header' => "Content-Type: application/json
" .
"Accept: application/json
" .
"Api-User: <API USER GOES HERE>
" .
"Api-Key: <API KEY GOES HERE>
"
)
);
$url = "https://url/paths";
$context = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );
$response = json_decode( $result );
I've searched this site and most of the examples seem to match up with what I'm doing...so I'm at a loss as to what the problem is. The one difference I noticed (vs. the examples) is that mine is posting to an HTTPS url...but from what I've read, that doesn't really make much of a difference. Any help you guys can provide would be greatly appreciated!