Java rest Web服务客户端
请帮助我为下面的rest服务创建rest客户端 端点url: 标题:内容类型:application/x-www-form-urlencoded;字符集=UTF-8 标题:授权:基本:base64编码的用户名和密码 正文:grant_type=password&username=xxx&password=yyyJava rest Web服务客户端,java,rest,service,client,Java,Rest,Service,Client,请帮助我为下面的rest服务创建rest客户端 端点url: 标题:内容类型:application/x-www-form-urlencoded;字符集=UTF-8 标题:授权:基本:base64编码的用户名和密码 正文:grant_type=password&username=xxx&password=yyy 非常感谢您的帮助。我在下面尝试过,不知道在哪里添加第二个标题和正文 String url = "http://xxx"; String name = "xxx";
非常感谢您的帮助。我在下面尝试过,不知道在哪里添加第二个标题和正文
String url = "http://xxx";
String name = "xxx";
String password = "yyy";
String authString = name + ":" + password;
String authStringEnc = new BASE64Encoder().encode(authString.getBytes());
System.out.println("Base64 encoded auth string: " + authStringEnc);
Client restClient = Client.create();
WebResource webResource = restClient.resource(url);
ClientResponse resp = webResource.accep`enter code here`t("application/json")
.header("Authorization", "Basic " + authStringEnc)
.get(ClientResponse.class);
if(resp.getStatus() != 200){
System.err.println("Unable to connect to the server");
}
String output = resp.getEntity(String.class);
System.out.println("response: "+output);
你想让我们为你写完整的代码吗?先试试你自己,带着障碍来。我已经发布了我的方法。什么是客户端、Web源、客户端响应?