Java調用http接口(x-www-form-urlencoded)

try { String postURL = "http://118.24.*.*:8080/Dar_TWS_Service.asmx/GetFromStation"; PostMethod postMethod = null; postMethod = new PostMethod(postURL) ; postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8") ; //參數設置,須要注意的就是裏邊不能傳NULL,要傳空字符串
            NameValuePair[] data = { new NameValuePair("_ArgStr","*") }; postMethod.setRequestBody(data); org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient(); int response = httpClient.executeMethod(postMethod); // 執行POST方法
            String result = postMethod.getResponseBodyAsString() ; System.out.println(response); System.out.println(result); } catch (Exception e) { // logger.info("請求異常"+e.getMessage(),e);
            throw new RuntimeException(e.getMessage()); }
相關文章
相關標籤/搜索