如何从 Rest Client 的响应对象中获取 url 对象
How to get url object from response object of Rest Client
我正在尝试解决下面提到的问题
查询此 Web 服务 100 次:
http://www.randomwebsite.com/cgi-bin/random.pl
响应包含一个简短的 HTML 文档,其中包含一个 link。查询此 link 并将 link URL 以及返回的 HTTP 响应代码存储在合适的数据结构中。
应用程序应输出所有 link URL 按域名第一个字符排序的列表(忽略 http:// 和 www 前缀)并打印相关的 HTTP 代码,如果它不是 200 .
我正在尝试使用球衣客户端
Client client = Client.create();
WebResource webResource2 = client.resource("http://www.randomwebsite.com/cgi-bin/random.pl");
ClientResponse response2 = webResource2.accept("text/html").get(ClientResponse.class);
System.out.println(response2);
if (response2.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + response2.getStatus());
}
String output2 = response2.getEntity(String.class);
System.out.println("\n============getFtoCResponse============");
System.out.println(output2);
GET http://www.westciv.com/ returned a response status of 200 OK
现在的问题是存储 URI 我无法获取 uri.How 从响应中获取 URI object.I 我能够在 response2 中看到随机 url 时它 printed.But 无法作为对象获取 URL.I 无法从客户端获取,因为随机网站重定向到随机站点。
发送的响应是重定向,状态为 302。您的客户端允许 not following redirects automatically:
client.setFollowRedirects(false);
您应该从 Location
响应 header 中得到 URL。
我正在尝试解决下面提到的问题
查询此 Web 服务 100 次:
http://www.randomwebsite.com/cgi-bin/random.pl
响应包含一个简短的 HTML 文档,其中包含一个 link。查询此 link 并将 link URL 以及返回的 HTTP 响应代码存储在合适的数据结构中。 应用程序应输出所有 link URL 按域名第一个字符排序的列表(忽略 http:// 和 www 前缀)并打印相关的 HTTP 代码,如果它不是 200 .
我正在尝试使用球衣客户端
Client client = Client.create();
WebResource webResource2 = client.resource("http://www.randomwebsite.com/cgi-bin/random.pl");
ClientResponse response2 = webResource2.accept("text/html").get(ClientResponse.class);
System.out.println(response2);
if (response2.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + response2.getStatus());
}
String output2 = response2.getEntity(String.class);
System.out.println("\n============getFtoCResponse============");
System.out.println(output2);
GET http://www.westciv.com/ returned a response status of 200 OK
现在的问题是存储 URI 我无法获取 uri.How 从响应中获取 URI object.I 我能够在 response2 中看到随机 url 时它 printed.But 无法作为对象获取 URL.I 无法从客户端获取,因为随机网站重定向到随机站点。
发送的响应是重定向,状态为 302。您的客户端允许 not following redirects automatically:
client.setFollowRedirects(false);
您应该从 Location
响应 header 中得到 URL。