2014-03-31 2 views
0

Wordpress Plugin을 사용하려면 CURL에서 wp_remote_post로 PHP 라이브러리를 변환해야합니다.CURL 요청을 Wordpress로 변환 wp_remote_post

참조 번호는 Wordpress wp_remote_post page here입니다.

어떤 시점에서

$THEurl = $scheme . $url['host'] . $url['path']; 
    $response = wp_remote_post($THEurl, array(
     'method' => 'POST', 
     'timeout' => 45, 
     'redirection' => 5, 
     'httpversion' => '1.0', 
     'blocking' => true, 
     'headers' => array(), 
     'body' => $query, 
     'cookies' => array() 
     ) 
    ); 

    if (is_wp_error($response)) { 
     $errorResponse = $response->get_error_message(); 
      require_once("FBAOutboundServiceMWS/Exception.php"); 
      curl_close($ch); 

      throw new FBAOutboundServiceMWS_Exception(array(
       'Message' => $errorResponse, 
       'ErrorType' => 'HTTP' 
      )); 
    } 

wp_remote_post을한다 ...

$ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, $scheme . $url['host'] . $url['path']); 
     curl_setopt($ch, CURLOPT_PORT, $port); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
     curl_setopt($ch, CURLOPT_USERAGENT, $this->_config['UserAgent']); 
     curl_setopt($ch, CURLOPT_POST, true); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $query); 
     curl_setopt($ch, CURLOPT_HEADER, true); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

     $response = ""; 
     $response = curl_exec($ch); 

     if ($response === false) { 
      $errorResponse = curl_error($ch); 
      require_once("FBAOutboundServiceMWS/Exception.php"); 
      curl_close($ch); 

      throw new FBAOutboundServiceMWS_Exception(array(
       'Message' => $errorResponse, 
       'ErrorType' => 'HTTP' 
      )); 
     } 

     curl_close($ch); 

이 내가 '생각'올바른 무엇지만 작동하지 않습니다 .. 제가 변환하려고 시도하는 코드입니다 실제로 사형 당해? 함수가 호출되었을 때? 사전에 도움을 많은 감사)

+0

슈퍼 유용한 정보 .- @Hobo –

+0

오류 코드가 있습니까? 오류 로그에 아무것도 표시되지 않습니까? 나는 네가하는 일에 많은 잘못을 느낀다. '$ query' 변수의 내용은 무엇입니까? 또한 내가 왜 잘못 curl_close() 오류 영역에서 실행하는지 모르겠다. – Stewartside

답변

2

나를 위해 이것을 시도하고

$THEurl = $scheme . $url['host'] . $url['path']; 
$response = wp_remote_post($THEurl, array(
    'method' => 'POST', 
    'timeout' => 45, 
    'redirection' => 5, 
    'httpversion' => '1.0', 
    'blocking' => true, 
    'headers' => array(), 
    'body' => $query, 
    'cookies' => array() 
    ) 
); 

if (is_wp_error($response)) { 
    $errorResponse = $response->get_error_message(); 
    require_once("FBAOutboundServiceMWS/Exception.php"); 

    throw new FBAOutboundServiceMWS_Exception(
     array(
      'Message' => $errorResponse, 
      'ErrorType' => 'HTTP' 
     ) 
    ); 
} else { 
    echo 'Response:<pre>'; 
    print_r($response); 
    echo '</pre>'; 
} 

당신이 필요하지 않은 코드를 툭 또한 응답의 인쇄에 추가 다시 무엇을 얻을 볼 수있는 너는 전에하지 않았어.

+0

이것은 내 답변을 이끌어 냈습니다. 'wp_remote_post'는 배열에서 데이터를 반환 했으므로 반환 응답이 사용 된 방식을 변경해야했습니다. 협조 해 주셔서 감사합니다. –