中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

HttpClient通過GET和POST獲取網(wǎng)頁內(nèi)容

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
最簡單的HTTP客戶端,用來演示通過GET或者POST方式訪問某個頁面
 
/**
 * 中國銀行支付網(wǎng)關(guān)---銀行回調(diào)的接口
 * @svncode <a href="svn://10.210.71.10/sinapay_bank/src/java/cn/com/sina">svn://10.210.71.10/sinapay_bank/src/java/cn/com/sina
 * @package cn.com.sina.pay.Bank.BOC
 * @author yuchao1@staff.sina.com.cn
 * @date 20101014
 * @access limited by password
 * @reference cn.com.sina.pay.ICBC
 * 
 */
import java.io.*;
import java.util.*;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.xml.sax.InputSource;

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
/**
 * 最簡單的HTTP客戶端,用來演示通過GET或者POST方式訪問某個頁面
 * @author yuchao
 */
public class HttpClient1{
    public static void main(String[] args) throws IOException
    {
        String merchantNo = "104110053004253";
        String orderNo = "101023416806";
        String signData = "SDJFALSF";
         
        HttpClient client = new HttpClient();
             
            //使用POST方法
            PostMethod postMethod = new PostMethod("<a href="https://ebspay.boc.cn/PGWPortal/QueryOrder.do">https://ebspay.boc.cn/PGWPortal/QueryOrder.do");
            /**
             * 使用POST方式提交數(shù)據(jù)
             */
          NameValuePair[] orderInfo = {new NameValuePair("merchantNo",merchantNo),new NameValuePair("orderNos",orderNo),
                  new NameValuePair("signData",signData),};
          postMethod.setRequestBody(orderInfo);

          client.executeMethod(postMethod);
           
          int code = postMethod.getStatusCode();  
          if (code == HttpStatus.SC_OK){
            String info = null;
            info = new String(postMethod.getResponseBodyAsString());
          }
           
          /**
           * 打印服務(wù)器返回的狀態(tài)
           */
          System.out.println("the post return value"+postMethod.getStatusLine());
          /**
           * 打印結(jié)果頁面
           */
          String response =   new String(postMethod.getResponseBodyAsString().getBytes("UTF-8"));
           /**
            * 打印返回的信息
            */
          System.out.println("the getBytes() xml is:"+response);
           //打印返回的信息
         String resCode = postMethod.getResponseBodyAsString();
         System.out.println("the is my other xml:"+resCode);
           //釋放連接
         postMethod.releaseConnection();
         
      
      
     StringReader read = new StringReader(resCode);
     InputSource source = new InputSource(read);
     SAXBuilder sb = new SAXBuilder();
      
     try{
        Document doc = sb.build(source);
        Element root = doc.getRootElement();
         
        System.out.println("the getName is:"+root.getName());
        List jiedian = root.getChildren();
        //獲得XML中的命名空間(XML中未定義可不寫)
        Namespace ns = root.getNamespace();
        Element et = null;
        List orderList = null;
         
        for (int i=0;i<jiedian.size();i++)
        {
            et = (Element)jiedian.get(i);
             
            if(et.getName().equals("header")){
                System.out.println(et.getChild("merchantNo", ns).getText());
                System.out.println(et.getChild("exception", ns).getText());
            }
             
            if(et.getName().equals("body")){
                orderList = et.getChildren();
            System.out.println(et.getChild("orderTrans", ns).getChild("orderStatus").getText());
            }
             
        }
        for (int i=0;i<orderList.size();i++)
        {
            et = (Element)orderList.get(i);
             
            if(et.getName().equals("orderTrans")){
                System.out.println(et.getChild("payTime", ns).getText());               
            }
             
        }
        }catch(JDOMException e){
            e.printStackTrace();
      }catch(IOException e){
            e.printStackTrace();
        }
   }
}

標簽: 服務(wù)器

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:mydumper備份數(shù)據(jù)庫腳本

下一篇:Golang網(wǎng)頁下載示例