我正在使用HttpURLConnection调用REST Web服务(这不是实际的URL和凭据,当然我在发布到公共论坛之前更改了值)...
String uri = "http://99.82.36.238:8443/media/crowd?";
String query = String.format("office_code=%s&content_type_code=%s",
URLEncoder.encode("USA"), URLEncoder.encode("SGV"));
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "text/xml");
String username = "userNewbie";
String password = "password";
conn.setRequestProperty("Authorization", CredentialsEncoder.userNamePasswordBase64(username,password));
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode() + " because " + conn.getResponseMessage());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
问题是我正在呼叫的服务在握手模式下不起作用。这意味着它需要我在第一次发出请求时发送信用,而不是发出请求并获得403然后发送信用。
有人可以建议如何修改上述代码以满足该要求吗?
感谢。