當沒有防火牆時,標準getUrlContent可以正常工作。但是當我嘗試在防火牆後面進行操作時,我遇到了異常情況。Android:無法在防火牆後面進行httprequest
我試圖在AVD管理器中設置「http代理服務器」,但它沒有工作。任何想法如何正確設置它?
and btw:from android documentation「您可以使用-verbose-proxy選項來診斷代理連接問題。」 -verbose-proxy根本不是一個有效的選項。
protected static synchronized String getUrlContent(String url) throws ApiException {
if(url.equals("try")){
return "thanks";
}
if (sUserAgent == null) {
throw new ApiException("User-Agent string must be prepared");
}
// Create client and set our specific user-agent string
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
request.setHeader("User-Agent", sUserAgent);
try {
HttpResponse response = client.execute(request);
// Check if server response is valid
StatusLine status = response.getStatusLine();
if (status.getStatusCode() != HTTP_STATUS_OK) {
throw new ApiException("Invalid response from server: " +
status.toString());
}
// Pull content stream from response
HttpEntity entity = response.getEntity();
InputStream inputStream = entity.getContent();
ByteArrayOutputStream content = new ByteArrayOutputStream();
// Read response into a buffered stream
int readBytes = 0;
while ((readBytes = inputStream.read(sBuffer)) != -1) {
content.write(sBuffer, 0, readBytes);
}
// Return result from buffered stream
return new String(content.toByteArray());
} catch (IOException e) {
throw new ApiException("Problem communicating with API", e);
}
}
我在windows下,我甚至找不到/data/data/com.google.android.providers.settings/databases/settings.db位置。文件位於何處? – Yang 2010-03-29 17:42:55
好吧,你需要進入模擬圖像的「殼」。 http://developer.android.com/guide/developing/tools/adb.html#shellcommands 這應該讓你在那裏爲你所需要的。 – 2010-03-29 19:55:23