quelqu'un peut me aider à traduire à un code PHP:cURL avec PHP/Travailler avec PUT et GET
curl -X GET --header "Accept: text/plain" "https://test:[email protected]:1443/rest/items/test/state"
et:
curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "OFF" "https://test:[email protected]:1443/rest/items/test/state"
Ma tentative a échoué. En général, j'utiliser ceci:
function sendCommand($item, $data) {
$url = "http://192.168.1.121:8080/rest/items/" . $item;
$options = array(
'http' => array(
'header' => "Content-type: text/plain\r\n",
'method' => 'POST',
'content' => $data //http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
Mais je ne sais pas comment ajouter SSL support et l'authentification au script et je sais que cela est plus facile avec cURL.
Merci, je l'ai déjà trouvé le moyen d'ajouter SSL et l'authentification à cURL. Mon problème est de traduire ceci: 'curl -X GET --header" Accepter: texte/plain "" https: // test: [email protected]: 1443/reste/items/test/état "' et ' curl -X PUT --header "Content-Type: text/plain" --header "Accepter: application/json" -d "OFF" "https: // test: testp[email protected]: 1443/rest/items/test/state "' à un script PHP. – Psycho0verload
Vérifiez la 2ème partie de ma réponse pour la partie authentification. Dans votre cas, il devrait être "test: testpassword". – Alex
Mon problème n'est pas le SSL et l'authentification. Mon problème est de convertir le script du shell curl en un script PHP – Psycho0verload