Hithere。UnknownHostException與Apache HTTPClient
我正在嘗試使用Apache的HTTPClient庫的DefaultHttpClient對URL執行GET。
這裏是我的代碼:
public String getHTML(String url) throws IOException, ClientProtocolException {
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
HttpHost targetHost = new HttpHost(url);
HttpGet httpGet = new HttpGet("/");
HttpResponse response = httpclient.execute(targetHost, httpGet);
HttpEntity entity = response.getEntity();
如果我通過一個URL,如 「www.google.ie」,我沒有問題。但是,如果我使用具有諸如「www.google.ie/intl/en/ads/」之類的相對路徑的網址,則該網址會失敗。我收到了上面httpclient.execute()
方法拋出的UnknownHostException。它只發生在相對的網址,我不知道爲什麼。有沒有人爲什麼輸入?非常感謝
對不起,我發現這個問題。我不得不將相對路徑傳遞給HTTPGet。道歉。 – Joeblackdev 2011-03-21 13:07:29