以POST方式发送

URL url = null;  

        String inputLine = null;  

        HttpURLConnection httpurlconnection = null;  

        try {  

        //取上级电警平台的url

            url = new URL(ConfigManager.getInstance().getConfigItem("urlDJ", ""));  

            httpurlconnection = (HttpURLConnection) url.openConnection();  

            httpurlconnection.setRequestProperty("Content-Type","application/json; charset=UTF-8");

            httpurlconnection.setRequestMethod("POST");  

            httpurlconnection.setConnectTimeout(500000);

            httpurlconnection.setDoOutput(true);  

            httpurlconnection.setDoInput(true);  

            httpurlconnection.setUseCaches(false);  

            httpurlconnection.getOutputStream().write(json.toString().getBytes());  

            httpurlconnection.getOutputStream().flush();  

            httpurlconnection.getOutputStream().close();  

//            int code = httpurlconnection.getResponseCode();  

            inputLine = readContents(httpurlconnection);  

        } catch (Exception e) {  

            e.printStackTrace();  

        } finally {  

            if (httpurlconnection != null)  

                httpurlconnection.disconnect();  

        }  

        InterfaceLogger.info("调用上级电警平台获取设备状态接口的返回值inputLine:" + inputLine);

        return inputLine;

 

posted @ 2018-09-05 15:34  萧韶九成  阅读(351)  评论(0编辑  收藏  举报