我已在模拟器中设置了代理设置,我可以在模拟器的浏览器上访问普通的互联网。但是当我尝试运行我的应用程序时,它会出错 但是,当我将URL更改为在组织内运行的服务时,我可以获取数据!!!
这里有什么问题,如何通过我的应用程序连接到我的组织外的URL ???
由于 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):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(母语 方法)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(母语 方法)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(母语 方法)
这是我的代码:
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();
}
});
答案 0 :(得分:0)
我没有太多时间来了解您实际需要的内容,但如果您想将代理应用于您的应用程序,请查看以下示例。
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
他们几乎是一样的。抱歉..祝你好运:))