我在java Jersey REST中開發了一個Web服務。我使用HttpClient來調用一個基本的GET方法。HttpClient不與本地主機工作
在瀏覽器上使用此URL http://localhost:8080/myserver/rest/location
時,它可以正常工作。
使用此代碼調用GET方法時,出現404 Not Found錯誤。
private static final String BASIC_URL = "http://localhost:8080/myserver/rest/location";
public static boolean isAlive() throws URISyntaxException, ClientProtocolException, IOException{
HttpClient httpclient = new DefaultHttpClient();
HttpGet get=new HttpGet(BASIC_URL);
System.out.println(get.getURI());
System.out.println("after adding all namevalues: "+get.getURI());
HttpResponse response = httpclient.execute(get);
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() != 200) {
System.out.println("response status="+statusLine.getStatusCode());
return false;
}
System.out.println("Response sent succesfully with status "+200);
return true;
}
任何線索?
UPDATE
而且,我想http://192.168.9.160:8080/LocationRetreiverServer/rest/location
(我的本地IP),它給了Not Found錯誤!
它在瀏覽器上顯示什麼? – 2013-04-24 13:49:58
它顯示200 OK響應並顯示一個字符串。 – 2013-04-24 13:58:40
你的澤西REST服務是否有可能返回404的邏輯? – 2013-04-24 14:05:21