【发布时间】:2016-12-28 12:02:18
【问题描述】:
我正在处理需要安全令牌的 POS 系统的 API 集成。在 API 文档和 curl 中,响应正常。
卷曲
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 需要什么?
【问题讨论】:
-
你在哪里测试这个 API 的?邮递员?
-
这是在 wordpress 中。我已经在邮递员中对此进行了测试,它也得到了相同的请求和错误消息