【问题标题】:Wordpress HTTP API code 400WordPress HTTP API 代码 400
【发布时间】: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 中。我已经在邮递员中对此进行了测试,它也得到了相同的请求和错误消息

标签: php wordpress api curl


【解决方案1】:

首先将 Basic Auth 更改为 oAuth 并像这样添加 JSON。

{
  "title": {
  "raw": "Hello Checking"
}

过去它对我有用。您应该对此进行调查并在 POSTMAN 中进行测试。

【讨论】:

    猜你喜欢
    • 2015-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-03
    • 2022-01-22
    • 2013-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多