将数据放入请求的所有可能方式 body

All possible ways to put data in request body

在我们的系统中,我们与另一个系统集成。

但是,我们觉得无法调用一些名为 api/esia/verify

的 API 方法

这是来自 swagger 的屏幕,其中包含必需的 header 和 body 内容

我试过像这样将密码输入 body:

  1. 作为普通实体
  2. 作为多部分实体
  3. 作为JSONobject

全部如下:

代码如下:

public static boolean finishAuthorization(final String bearerToken, final String password) throws IOException 
    {       
        CloseableHttpClient httpclient = HttpClients.createDefault();
        try
        {
            HttpPut httpPut = new HttpPut("urlToSendTo");
            StringEntity se = new StringEntity(password); // first case
            /* MultipartEntityBuilder builder = MultipartEntityBuilder.create();
            builder.addTextBody("password", password);
            HttpEntity entity = builder.build();
            httpPut.setEntity(entity); */ // second case
            /* StringEntity se = new StringEntity(new JSONObject().put("password", password).toString()); */ // third case

            httpPut.setEntity(se);

            EGRZHttpUtils.addHeadersToHttp(httpPut, new HashMap<String, String>(){{
                put("Authorization", bearerToken);
                put("Content-Type", "application/json;charset=UTF-8");
            }});

            HttpResponse response = httpclient.execute(httpPut);
            System.out.println("response status " +  response.getStatusLine().getStatusCode());
            return Boolean.valueOf(EntityUtils.toString(response.getEntity()));
        }
        finally
        {
            httpclient.close();
        }
    }

我使用的HTTP客户端是org.apache.http

但不幸的是,上述 none 工作正常。我正在集成的系统一直说 password 未提供且不能 null。由于缺少文档,我必须了解是否有其他方法可以将内容添加到 body 并且可以在我这边修复或者他们的配置是否错误。

提前致谢。

编辑

我可以使用他们的服务进行测试。无法使用 Swagger 进行测试,因为 Token 经常更新,而且它 returns 我 401(未授权)

在他们的网站上,我可以调用相同的方法,它 returns true/false 正如预期的那样。

request payload 中有 - password。但是我不知道怎么看原始的。

是否有 chrome 对 see/convert 的扩展,就像 Wireshark 一样?

嗯,原来密码实体应该用双引号引起来:x

只有在这种情况下它才能"see"它..

让我无语不用说