我制作了一个接受 xml 数据的应用程序,但是当我发送对该资源的查询时,看起来没有连接。我添加了 android 互联网权限并在浏览器中有网络,但在我的应用程序中没有任何连接。
这是代码
受保护的字符串发送请求(字符串 urlAdr,ArrayList postVars){ 字符串数据=extractPairValuesToString(postVars); urlAdr+=数据;//发送url中的所有变量,而不是来自请求属性 字符串 xmlResponse=null; HttpURLConnection con = null; 网址网址; 尝试 { url = 新 URL(urlAdr); con = (HttpURLConnection) url.openConnection(); //con.setReadTimeout(10000 /* 毫秒 */); //con.setConnectTimeout(15000 /* 毫秒 */); 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()); } }