2014-02-07 6 views
3

내가 CURL을 사용하여 PUT 요청을 보내도록 노력하고 있어요,하지만 난 HTTP 400 잘못된 요청, 내가 디버그에 CURLOPT_VERBOSE를 사용하고 그와 나는 점점 오전 점점 오전 : "오류 : 잘못된 요청 : 예상 개체 : \ "이메일 \" "}이게 무슨 뜻인지/어떻게 해결할 수 있는지 아는 사람 있습니까?HTTP 400 잘못된 요청 - CURL PHP

코드 :

// Set the HTTP headers needed for this API call. 

$http_headers = array(
// "Authorization: Basic xxxxxxxxxxxxxxxxxx", 
"Accept: application/json", 
"Connection: close",     // Disable Keep-Alive 
"Expect:",        // Disable "100 Continue" server response 
"Content-Type: application/json"  // Content Type json 
); 

// URL Endpoint of the API to be called. 
$ym_api_url = 'https://services.yesmail.com/enterprise/subscribers/718880'; 
$newsubscriber = array(
'email' => '[email protected]', 
'firstName' => 'Karina', 
'lastName' => 'McG', 
'postCode' => 'BT93 EP3', 
'prefersMobile' => '', 
'emailFormat' => 'HTML' 
); 

$curl_hdl = curl_init(); 

$curl_options = array(
CURLOPT_VERBOSE => TRUE,    // Verbose mode for diagnostics 
CURLOPT_STDERR => $verbose = fopen('php://temp', 'rw+'),   // Verbose output to STDERR 
CURLOPT_HEADER => TRUE,    // Include the header in the output. 
CURLOPT_HTTPHEADER => $http_headers, // HTTP headers to set 
CURLOPT_HTTPAUTH => CURLAUTH_BASIC, // Use basic authentication. 
CURLOPT_USERPWD => 'xxxxxxx:xxxxxxxx', //Username/Password 
CURLOPT_PROTOCOLS => CURLPROTO_HTTPS, // Bitmask of protocols libcurl may use in this transfer 
CURLOPT_RETURNTRANSFER => TRUE,  // Return result as return value of curl_exec() 
CURLOPT_URL => $ym_api_url,   // URL to POST data to 
); 
curl_setopt_array($curl_hdl, $curl_options); 

//Send array to URL 
curl_setopt($curl_hdl, CURLOPT_CUSTOMREQUEST, "PUT"); 
curl_setopt($curl_hdl, CURLOPT_POSTFIELDS, http_build_query($newsubscriber)); 

//SSL Bypass (!Temporary!) 
curl_setopt($curl_hdl, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($curl_hdl, CURLOPT_SSL_VERIFYPEER, 0); 

// Make the API call 
$response = curl_exec($curl_hdl); 

// Get the http response code 
$http_response_code = curl_getinfo($curl_hdl, CURLINFO_HTTP_CODE); 

// Echo out the Verbose Information 
echo "Verbose information:\n<pre>", !rewind($verbose), htmlspecialchars(stream_get_contents($verbose)), "</pre>\n"; 
curl_close($curl_hdl); 

echo PHP_EOL . "INFO: HTTP Response Code was: " . $http_response_code . PHP_EOL; 

if ($response === false) 
{ 
echo PHP_EOL . "ERROR: curl_exec() has failed." . PHP_EOL; 
} 
else 
{ 
echo PHP_EOL . "INFO: Response Follows..." . PHP_EOL; 
echo PHP_EOL . $response; 
} 
+0

json을 보내는 헤더에 지정하고 있지만 코드에 json이 표시되지 않습니다. 엔드 포인트에 필요한 형식은 무엇입니까? –

+0

json 또는 xml –

+0

ok이지만 json이나 xml에서는 데이터를 보내지 않습니다. 먼저 변환해야합니다. –

답변

3

이 나쁜 요청하면 컬에서하지에 도달하려고하는 서비스에서오고있다. 따라서 올바른 형식으로 데이터를 전송해야합니다.