簡體   English   中英

HTTP 400錯誤請求 - CURL PHP

[英]HTTP 400 Bad Request - CURL PHP

我正在嘗試使用CURL發送PUT請求,但我收到HTTP 400 Bad Request ,我正在使用CURLOPT_VERBOSE進行調試,並且我得到: “錯誤:格式錯誤的請求:期望找到的對象:\\”email \\“”}有誰知道這意味着什么/我如何解決?

碼:

// 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' => 'karina@email.com',
'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;
}

糟糕的請求來自您嘗試聯系的服務,而不是來自curl。 因此,您需要確保以正確的格式向他們發送數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM