2015-04-18 34 views
1

Я пытаюсь отправить эти данные json через php и не имея удачи.Преобразование командной строки curl в php-код

curl --header 'Authorization: Bearer <token>' -X POST https://api.site.com --header 'Content-Type: application/json' --data-binary '{"email": "[email protected]", "type": "note", "title": "title", "body": "Note Body"}' 

Вот что у меня есть:

 curl_setopt_array($ch = curl_init(), array(
     CURLOPT_HTTPHEADER => array("Authorization: Bearer <token>", "Content-Type: application/json"), 
     CURLOPT_URL => "https://api.site.com", 
     CURLOPT_POST => true, 
     CURLOPT_BINARYTRANSFER => true, 
     CURLOPT_RETURNTRANSFER => true, 
     CURLOPT_POSTFIELDS => array(
     "email" => "[email protected]", 
     "type" => "note", 
     "title" => "alert", 
     "body" => "body", 
    ), 
     CURLOPT_SAFE_UPLOAD => true, 
    )); 
    $response = curl_exec($ch); 
    curl_close($ch); 

ответ

2

Попробуйте как CURLOPT_POSTFIELDS => json_encode(array( "email" => "[email protected]", "type" => "note", "title" => "alert", "body" => "body", )),

+0

Спасибо, что была проблема. Просто там, где я не смотрел. Если бы я мог, я бы поднял голову. – bbglazer

+0

Без проблем, рад, что я мог бы помочь ;-) Вы можете принять это как ответ :-) –

Смежные вопросы