---
title: "分析Http请求头获取爱帮公交数据"
author: "yzyspy"
date: "2012-10-20T20:43:27Z"
tags: []
categories: ["移动开发"]
slug: "http"
draft: false
lastmod: "2012-10-20T20:44:10Z"
id: 1702287
url: "https://yzyspy.iteye.com/blog/1702287"
---

爱帮公交公布了自己的openAPI，但是之前自己不知道，就通过chrome的开发人员控制台工具分析了爱帮工具的http请求头，然后在android端进行http请求，获得公交信息。

还算顺利，其中的一点曲折就是服务器端返回的是 zip压缩的数据，要使用ziphelper进行解压缩。

 

 

```
 String url="http://wap.aibang.com:8081/client/servlet/busline.c?city=北京&keyword=618&s=android_noxy";
        HttpGet httpGet = new HttpGet(url);     
        httpGet.addHeader("PLATFORM_N", "abbus_android");
        httpGet.addHeader("CLIENT_V", "abbus_android_v3.0");
        httpGet.addHeader("CONTENT_TYPE", "pzip");
        httpGet.addHeader("ENCODING", "utf-8");
        httpGet.addHeader("UID", "b239cc83f23c4dab90fe6a27e329dea73b7a052");
        httpGet.addHeader("SOURCE", "0");
        httpGet.addHeader("UA", "sdk,8,2.2,sdk-eng 2.2 FRF91 43546 test-keys,Unknown,null");

        HttpClient httpclient = new DefaultHttpClient();            
        //请求HttpClient，取得HttpResponse               
        HttpResponse httpResponse;
		try {
			httpResponse = httpclient.execute(httpGet);
			
			if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK)  {    
	        //    String strResult = EntityUtils.toString(httpResponse.getEntity().getContent());
			    InputStream is = httpResponse.getEntity().getContent();
				is = new GZipInputStream(is, GZipInputStream.TYPE_GZIP, false);

         		BufferedReader br = new BufferedReader(new InputStreamReader(is));
         		String line;
         		StringBuilder sb =  new  StringBuilder();  
         		while ((line = br.readLine()) != null) {
         			sb.append(line);
         		}
         	   String s = sb.toString();
         	   
         	   Toast.makeText(this, s, Toast.LENGTH_LONG).show();
         	  
	        }
		}
```