我對JBoss的它調用另一個休息web服務託管一個Java休息API:調用其他API
@GET
@Path("/testDeployment")
@Produces(MediaType.TEXT_PLAIN)
public String testDeployment() {
URL url = new URL(restURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", "Bearer "+sessionId);
System.out.println("sessionId>>>> "+sessionId);
System.out.println("restURL>>>> "+restURL);
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
response += output;
}
conn.disconnect();
}
但我得到錯誤
服務器返回的HTTP響應代碼:401網址:https://cs5.salesforce.com/services/apexrest/event/search?type=init
13:16:08738 ERROR [stderr的](默認任務-26)產生java.io.IOException:服務器返回的HTTP響應代碼:401爲URL:https://cs5.salesforce.com/services/apexrest/event/search?type=init
13:16:08747 ERROR [stderr的](默認任務-26)在sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840)
我使用相同的代碼來調用使用java類的外部web服務,它運行良好 –