android - emulator - internet connection issue -
i have set proxy settings in emulator , can access normal internet on emulator's browser. when try run application, gives error when change url services running inside organisation can fetch data!!!
what issue here , how connect urls outside org through app???
thanks abhinav tyagi
error:
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):
@ org.apache.harmony.luni.internal.net.www.protocol.http.httpurlconnectionimpl.getinputstream(httpurlconnectionimpl.java:1162) 05-11 17:12:28.917: warn/system.err(847): @ com.xml.xml_test.getxml(xml_test.java:65) 05-11 17:12:28.928: warn/system.err(847): @ java.lang.reflect.method.invokenative(native method) 05-11 17:12:28.939: warn/system.err(847): @ java.lang.reflect.method.invoke(method.java:521) 05-11 17:12:28.957: warn/system.err(847): @ android.view.view$1.onclick(view.java:2067) 05-11 17:12:28.957: warn/system.err(847): @ android.view.view.performclick(view.java:2408) 05-11 17:12:28.968: warn/system.err(847): @ android.view.view$performclick.run(view.java:8816) 05-11 17:12:28.968: warn/system.err(847): @ android.os.handler.handlecallback(handler.java:587) 05-11 17:12:28.989: warn/system.err(847): @ android.os.handler.dispatchmessage(handler.java:92) 05-11 17:12:28.989: warn/system.err(847): @ android.os.looper.loop(looper.java:123) 05-11 17:12:29.007: warn/system.err(847): @ android.app.activitythread.main(activitythread.java:4627) 05-11 17:12:29.007: warn/system.err(847): @ java.lang.reflect.method.invokenative(native method) 05-11 17:12:29.007: warn/system.err(847): @ java.lang.reflect.method.invoke(method.java:521) 05-11 17:12:29.007: warn/system.err(847): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) 05-11 17:12:29.007: warn/system.err(847): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) 05-11 17:12:29.037: warn/system.err(847): @ dalvik.system.nativestart.main(native method)
here code:
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); = conn.getinputstream(); long len = 0; int ch = 0; len = conn.getcontentlength(); if (len != -1) { // read content-length bytes system.out.println("if..."); (int = 0; < len; i++) { system.out.println("for loop..."); if ((ch = is.read()) != -1) { system.out.println("appending"); b.append((char) ch); } } } else { // read till connection 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(); } });
i dont have time go through need if wanna apply proxy application check following examples..
http://www.jguru.com/faq/view.jsp?eid=13186
http://www.rgagnon.com/javadetails/java-0085.html
http://www.java2s.com/code/java/network-protocol/urlconnectionandproxy.htm
they're pretty same. sorry.. , luck :)
Comments
Post a Comment