Witam.
Nie mam żadnego doświadczenia w php, ale potrzebuje zrobić małe podłączenie do webApi, robię to w ten sposób:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "$url",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer '.$auth,
'Content-Type: application/json',
),
));
$response = curl_exec($curl);
curl_close($curl);
Wszystko mi działa do momentu, w którym musze przesłać przez API parametry json, np.
{
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!",
"body": "The shortest article. Ever.",
"created": "2015-05-22T14:56:29.000Z",
"updated": "2015-05-22T14:56:28.000Z"
},
"relationships": {
"author": {
"data": {"id": "42", "type": "people"}
}
}
}],
"included": [
{
"type": "people",
"id": "42",
"attributes": {
"name": "John",
"age": 80,
"gender": "male"
}
}
]
}
Próbowałem na wiele sposóbów, wrzucałem do HTTPHEADER itp, ale za każdym razem dostaje błąd:(bez podawania parametrów nie dostaje tego błędu i wszystko działa)
<html><body><h1>400 Bad request</h1>
Your browser sent an invalid request.
</body></html>
Mógłby mi ktoś podpowiedzieć jak dodać tego jsona do mojego kodu? Pozdrawiam.