日期:2014-05-17  浏览次数:21033 次

请教高手.关于PrintWriter和HttpURLConnection的异常问题
URL url=null;
HttpURLConnection http=null;
ResourceBundle rb=ResourceBundle.getBundle("app");
try{
url=new URL(rb.getString("m2m.map.geourl"));
http=(HttpURLConnection)url.openConnection();
http.setDoOutput(true);
http.setDoInput(true);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(http.getOutputStream(),"UTF-8"));
pw.write(getXML(longitude,latitude));




报以下异常
java.net.ConnectException: Connection timed out
  at java.net.PlainSocketImpl.socketConnect(Native Method)
  at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
  at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
  at java.net.Socket.connect(Socket.java:519)
  at java.net.Socket.connect(Socket.java:469)
  at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
  at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
  at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
  at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
  at sun.net.www.http.HttpClient.New(HttpClient.java:306)
  at sun.net.www.http.HttpClient.New(HttpClient.java:323)
  at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:788)
  at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:729)
  at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:654)
  at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:832)
  at com.sitech.common.util.MapUtil.reGeo(MapUtil.java:120)
  at com.sitech.wcmp.service.WcmpService.location(WcmpService.java:212)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:194)
  at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:98)
  at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
  at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:96)
  at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:145)
  at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
  at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:120)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
  at com.sitech.common.util.CharacterEncodingFilte