我正在研究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"
请求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: 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中需要什么?
首先将Basic Auth更改为oAuth,并像这样添加JSON。
{
"title": {
"raw": "Hello Checking"
}
过去它对我有用。您应该研究一下这个问题并在POSTMAN中进行测试。