webservice接口的访问&&调用&&webservice的封装

http://rcfeng.iteye.com/blog/1631280

封装接口和调用接口

 

访问接口:

URL postUrl = new URL("http:www");
            HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection();
            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setRequestMethod("POST");
            connection.setUseCaches(false);
            connection.setInstanceFollowRedirects(true);
            connection.setRequestProperty("contentType", "utf-8");
            connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
            connection.connect();
            DataOutputStream out = new DataOutputStream(connection
                    .getOutputStream());
            String info = "{\"mobile\":\""+phoneNum+"\",\"type\":\"ownVoiceMail\",\"phoneNumber\":\""+phoneNum+"\"}";
            String content = "info=" + URLEncoder.encode(com.zhiyou.comm.util.AESUtils.encrypt4AES(info,"c8d62969ffdce52d"), "UTF-8");
            out.writeBytes(content);

            out.flush();
            out.close(); 

            StringBuilder builder= new StringBuilder("");
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8"));
            String line;
            while ((line = reader.readLine()) != null){
            	builder.append(line);
//            	
            }
            String result = builder.toString();
          
            reader.close();
            connection.disconnect();

 

 

 

 

你可能感兴趣的:(webservice接口的访问&&调用&&webservice的封装)