curl 명령을 wp_remote_request 명령으로 변환하려고합니다. 여기wp_remote_request 명령에 curl 명령
curl -v
-H "Accept:application/json" -H "Content-type:application/json"
-X POST -d '{"user":{"password":"***","email":"***"}}'
http://***/users/sign_in.json
그리고 문제는 그냥 작동하지 않을 것입니다 내 PHP
$t = array(
"user" => array(
"password" => "***",
"email" => "***"));
$args = array (
'headers' =>
array (
'Accept' => 'application/json',
'Content-Type' => 'application/json',
),
'method' => 'POST',
'body' => json_encode($t)
);
$response = wp_remote_request(
'http://***/users/sign_in.json' , $args);
입니다 :
다음은 curl 명령이다. 나는 '몸'에 넣은 것에 따라 다른 오류를 얻지 만 대개 '404'라고합니다. 내가 생각할 수있는 유일한 것은 curl -d가 어떻게 든 요청을 인코딩하지만, 나는 그 방법을 이해할 수 없다는 것이다. 이견있는 사람? 감사. 그런데
다음은 잘 작동하지만 다시 내가 어젯밤 wp_remote_request 싸우고
$t = array('user' => array('password' => '***',
'email' => '***'));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://***/users/sign_in.json',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => json_encode($t),
CURLOPT_HTTPHEADER => array('Content-Type: application/json')
));
$resp = curl_exec($curl);
curl_close($curl);