我制作了一个接受xml数据的应用程序,但是当我发送此资源的查询时,看起来没有连接。我添加了Android互联网权限,并在浏览器中有网络,但在我的应用程序中没有任何连接。适用于Android 2.2但不适用于Android 2.3
这是代码
protected String sendRequest(String urlAdr,ArrayList postVars){ String data=extractPairValuesToString(postVars); urlAdr+=data; //send all variables in the url not from request properties String xmlResponse=null; HttpURLConnection con = null; URL url; try { url = new URL(urlAdr); con = (HttpURLConnection) url.openConnection(); //con.setReadTimeout(10000 /* milliseconds */); //con.setConnectTimeout(15000 /* milliseconds */); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); con.setRequestProperty("Connection", "Keep-Alive"); con.setRequestProperty("Content-Length", ""+Integer.toString(data.getBytes().length)); con.setDoInput(true); con.setDoOutput(true); }catch (IOException e) { setErrorStatus(e.getMessage()); } }
你得到任何异常(除IOException异常,甚至IOException异常)? –
不,任何异常都没有提交 – user1106234