我需要從連接到其他網址後,我從xml給出的url下載一個文件。我的問題是,我需要相同的用戶代理和IP來執行這兩個操作。url.getContent()上的用戶代理;
要獲得XML,我用的是我的服務器上承載的PHP代碼,我把它我的應用程序的用戶代理:
String ua=new WebView(ct).getSettings().getUserAgentString().trim();
ua = ua.replaceAll(" ", "%20");
然後我解析XML與通用RssParserSax,讓我我所需要的。
後,我嘗試將文件下載到繪製var和我這樣做:
Drawable dd = ImageOperations(url);
private Drawable ImageOperations(String url) {
try {
InputStream is = (InputStream) this.fetch(url);
Drawable d = Drawable.createFromStream(is, "src");
return d;
} catch (MalformedURLException e) {
return null;
} catch (IOException e) {
return null;
}
}
private Object fetch(String address) throws MalformedURLException,IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}
但正如我不發送用戶代理,它不給我任何東西。