我已經在模擬器中設置了我的代理設置,我可以在模擬器的瀏覽器上訪問普通的互聯網。但是當我嘗試運行我的應用程序時,它會給出錯誤 但是,當我將URL更改爲在組織內運行的服務時,我可以獲取數據!模擬器 - 互聯網連接問題
這裏有什麼問題,如何通過我的應用程序連接到我的組織之外的URL?
感謝 阿比納夫·特亞吉
錯誤:
05-11 17:12:28.867: WARN/System.err(847): java.io.FileNotFoundException: http://google.co.in 05-11 17:12:28.917: WARN/System.err(847):
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:1162) 05-11 17:12:28.917: WARN/System.err(847): at com.xml.xml_test.getXML(xml_test.java:65) 05-11 17:12:28.928: WARN/System.err(847): at java.lang.reflect.Method.invokeNative(Native Method) 05-11 17:12:28.939: WARN/System.err(847): at java.lang.reflect.Method.invoke(Method.java:521) 05-11 17:12:28.957: WARN/System.err(847): at android.view.View$1.onClick(View.java:2067) 05-11 17:12:28.957: WARN/System.err(847): at android.view.View.performClick(View.java:2408) 05-11 17:12:28.968: WARN/System.err(847): at android.view.View$PerformClick.run(View.java:8816) 05-11 17:12:28.968: WARN/System.err(847): at android.os.Handler.handleCallback(Handler.java:587) 05-11 17:12:28.989: WARN/System.err(847): at android.os.Handler.dispatchMessage(Handler.java:92) 05-11 17:12:28.989: WARN/System.err(847): at android.os.Looper.loop(Looper.java:123) 05-11 17:12:29.007: WARN/System.err(847): at android.app.ActivityThread.main(ActivityThread.java:4627) 05-11 17:12:29.007: WARN/System.err(847): at java.lang.reflect.Method.invokeNative(Native Method) 05-11 17:12:29.007: WARN/System.err(847): at java.lang.reflect.Method.invoke(Method.java:521) 05-11 17:12:29.007: WARN/System.err(847): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 05-11 17:12:29.007: WARN/System.err(847): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 05-11 17:12:29.037: WARN/System.err(847): at dalvik.system.NativeStart.main(Native Method)
這裏是我的代碼:
StringBuffer b = new StringBuffer();
System.out.println("try");
String registrationUrl = "http://google.com";
url = new URL(registrationUrl);
System.out.println("url");
URLConnection connection = url.openConnection();
System.out.println("open connection");
conn = (HttpURLConnection) connection;
int responseCode = conn.getResponseCode();
System.out.println(responseCode);
is = conn.getInputStream();
long len = 0;
int ch = 0;
len = conn.getContentLength();
if (len != -1) {
// Read exactly Content-Length bytes
System.out.println("IF...");
for (int i = 0; i < len; i++) {
System.out.println("For Loop...");
if ((ch = is.read()) != -1) {
System.out.println("Appending");
b.append((char) ch);
}
}
} else {
// Read till the connection is closed.
System.out.println("Else...");
while ((ch = is.read()) != -1) {
System.out.println("When...");
len = is.available();
System.out.println("append");
b.append((char) ch);
}
}
String data = b.toString();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(data).setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
xml_test.this.getParent();
}
});
你可以請張貼您的代碼?謝謝 – Rejinderi 2011-05-11 11:50:49
我已經添加了我的代碼,但它的工作正常與代理內的URL! 響應代碼即將到達403 – 2011-05-11 12:14:38
您的意思是您想要在您的應用程序上應用代理,以便它可以像網頁瀏覽器一樣通過代理訪問互聯網? – Rejinderi 2011-05-11 12:34:16