我正在从需要安全令牌的POS系统开始API集成。在API文档&卷曲响应是好的。
卷曲
curl -X POST --header "Content-Type: application/json" --header "Accept: */*" -d "{
\"deviceId\": \"api\",
\"password\": \"password\",
\"username\": \"ursername@pos.com\"
}" "http://staging-exact-integration.posios.com/PosServer/rest/token"
请求网址
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: org.eclipse.jetty.server.HttpInput@62421932; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input\n at [Source: org.eclipse.jetty.server.HttpInput@62421932; 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" => "username@pos.com"
)
);
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>';
}
Wordpress HTTP API需要什么?
答案 0 :(得分:0)
首先将Basic Auth更改为oAuth并添加JSON,就像这样。
{
"title": {
"raw": "Hello Checking"
}
它过去对我有用。您应该查看这个并在POSTMAN中进行测试。