首页 > 编程语言 > 详细

java爬虫:在请求body中增加json数据采集

时间:2015-11-24 12:56:06      阅读:519      评论:0      收藏:0      [点我收藏+]

1,http://www.hqepay.com/public/expressquery.html 

查询快递不是将键值对post过去,而是将json数据放到body中发送过去。抓包如下:

 

技术分享

 

2,需要导入一些包,代码如下:

import java.io.UnsupportedEncodingException;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class Main {

    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub

        DefaultHttpClient client = new DefaultHttpClient();
        String url = "http://www.hqepay.com/common/WebAdapter.aspx";
        HttpPost request = new HttpPost(url);
        request.addHeader("Accept", "application/json, text/javascript, */*; q=0.01");
        request.addHeader("X-Requested-With","XMLHttpRequest");
        request.addHeader("Referer", "http://www.hqepay.com/public/expressquery.html?ECode=ZJS&barNo=8466878151&lab=0");
        request.addHeader("Host","www.hqepay.com");
        String param =  "{\"FunClassName\":\"HqewPay.ExpBLL.ExpOnlineOrderBLL\",\"FunMethodName\":\"IndexTraceInfo\",\"ParamClassName\":\"HqewPay.Express.ExpParam\",\"ParamType\":\"Entity\",\"ParamData\":\"{\\\"ExpNo\\\":\\\"8466878151\\\",\\\"ExpCode\\\":\\\"\\\",\\\"ExpName\\\":\\\"ZJS\\\",\\\"parentCode\\\":\\\"ZJS\\\"}\"}";
        StringEntity se = new StringEntity(param); 
        request.setEntity(se);
        HttpResponse httpResponse = client.execute(request);
        String retSrc = EntityUtils.toString(httpResponse.getEntity());
        System.out.println(retSrc);
        
    }

}

 

java爬虫:在请求body中增加json数据采集

原文:http://www.cnblogs.com/wang7/p/4991190.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!