Android之用HttpURLConnection参数以XML形式封装的部分关键代码

113 阅读1分钟

HttpURLConnection参数以XML形式封装

 

 //得到连接
    public static HttpURLConnection setRequest(String urlStr) {
        HttpURLConnection con = null;
        try {
            URL url = new URL(urlStr);
            try {
                con = (HttpURLConnection) url.openConnection();
                con.setDoOutput(true);
                con.setDoInput(true);
                con.setRequestProperty("Pragma:", "no-cache");
                con.setRequestMethod("POST");
                con.setRequestProperty("Cache-Control", "no-cache");
                con.setRequestProperty("Content-Type", "text/xml");
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return con;
    }


请求参数xml的封装,以注册为例子

 

 <