2015-01-13 3 views
0

제 문제는 제가 지금까지 wordpress 플러그인 중 하나 인 에 POST 요청을했지만 지금은 wp_remote_post()을 사용해야합니다.WordPress cURL 및 wp_remote_post

wp_remote_post 나는 간단하게 보이지만 제대로 작동하지 않습니다. 그럼 내 질문은 : 누군가가 내wp_remote_post로 전송할 수있는 방법을 보여줄 수 있을까요?

컬 : 승인이 작동하지 않았기 때문에 wp_remote_post

$result = wp_remote_post($url, array(
    'method' => 'POST', 
    'headers' => $headers, 
    'body' => json_encode($fields)) 
); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); 
$result = curl_exec($ch); 
curl_close($ch); 

내 버전은 내가 wp_remote_post로 401 오류가 발생합니다.

답변

1

해결했습니다. 어떤 이유로 httpversion 및 sslverify를 추가 한 후 현재 작동 중입니다. 희망이있어 누군가를 도울 수 있습니다.

$result = wp_remote_post($url, array(
     'method' => 'POST', 
     'headers' => $headers, 
     'httpversion' => '1.0', 
     'sslverify' => false, 
     'body' => json_encode($fields)) 
    );