如何在Rest Client API中的POST请求中传递用于身份验证的多个参数?

时间:2019-06-26 10:40:07

标签: java json rest rest-client

在POSTMAN中: POST:http://localhost:8080/HHHHHH/IIIII

RAW: ({“ databaseid”:“ db12345”,  “ username”:“ rshg123”, “密码”:“ rf51315” })

漂亮的身体: {“ message”:“ rs67627282 | created”,    “状态:“已创建”,   “连接”:{           “ connectionid”:“ rs67627282” }, “代码”:“ 201” }

我想通过调用rest api在Java代码中实现此功能,下面以注释的形式给出了实际代码。指实现Java代码,该代码用于在Java控制台中调用POST请求并获取respose(上面给出的“ Pretty body”)。

public class RestApiClient { 
  public static void main(String[] args) { 
    // TODO Auto-generated method stub 
    Client client = ClientBuilder.newClient(); // how to pass multiple value here as POST request 
    HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("username", "password"); 
    client.register(feature); 
    // here i want to use post request Response 
    response = client.target("localhost:8080").request().get(); 
    System.out.println(response); 
  }
}

0 个答案:

没有答案