Я работаю над интеграцией API из POS-системы, для которой требуется токен безопасности. В документации API & завиток ответ в порядке.Код API-интерфейса Wordpress 400
Curl
curl -X POST --header "Content-Type: application/json" --header "Accept: */*" -d "{
\"deviceId\": \"api\",
\"password\": \"password\",
\"username\": \"[email protected]\"
}" "http://staging-exact-integration.posios.com/PosServer/rest/token"
URL запроса
http://staging-exact-integration.posios.com/PosServer/rest/token
Однако, когда я попытался записать его в Wordpress HTTP API я получаю 400 плохой запрос. Говоря
[body] => {"description":"Could not read JSON: No content to map due to end-of-input\n at [Source: [email protected]; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input\n at [Source: [email protected]; line: 1, column: 1]"}
В Wordpress
$url = "http://staging-exact-integration.posios.com/PosServer/rest/token";
$response = wp_remote_post($url, array(
"headers" => array(
//"Authorization" => "Basic",
"Content-Type" => "application/json"
),
//"body" => "grant_type=client_credentials",
//"httpversion" => "1.1",
"deviceId" => "api",
"password" => "password",
"username" => "[email protected]"
)
);
if (is_wp_error($response)) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
} else {
echo 'Response:<pre>';
print_r($response);
echo '</pre>';
}
Что требуется в HTTP API Wordpress?
Где вы тестировали этот API? Почтальон? – Noman
это в Wordpress. Я проверил это в почтальоне, а также получил тот же запрос и ошибку mesage – mark5