Created
September 29, 2010 12:14
-
-
Save shaobin0604/602652 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example; | |
| import java.io.IOException; | |
| import java.io.UnsupportedEncodingException; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| import org.apache.http.HttpEntity; | |
| import org.apache.http.HttpResponse; | |
| import org.apache.http.NameValuePair; | |
| import org.apache.http.client.ClientProtocolException; | |
| import org.apache.http.client.entity.UrlEncodedFormEntity; | |
| import org.apache.http.client.methods.HttpPost; | |
| import org.apache.http.impl.client.DefaultHttpClient; | |
| import org.apache.http.message.BasicNameValuePair; | |
| import org.apache.http.protocol.HTTP; | |
| import org.apache.http.util.EntityUtils; | |
| public class TestTicketLeft { | |
| public static void main(String[] args) throws ClientProtocolException, IOException { | |
| DefaultHttpClient httpClient = new DefaultHttpClient(); | |
| HttpPost httpost = new HttpPost( | |
| "http://dynamic.12306.cn/TrainQuery/iframeLeftTicketByStation.jsp"); | |
| List<NameValuePair> nvps = new ArrayList<NameValuePair>(); | |
| nvps.add(new BasicNameValuePair("arriveStation_ticketLeft", "上海")); | |
| nvps.add(new BasicNameValuePair("arriveStation_ticketLeft_new_value", "true")); | |
| nvps.add(new BasicNameValuePair("lx", "00")); | |
| nvps.add(new BasicNameValuePair("name_ckball", "value_ckball")); | |
| nvps.add(new BasicNameValuePair("nday3", "05")); | |
| nvps.add(new BasicNameValuePair("nday3_new_value", "false")); | |
| nvps.add(new BasicNameValuePair("nmonth3", "09")); | |
| nvps.add(new BasicNameValuePair("nmonth3_new_value", "true")); | |
| nvps.add(new BasicNameValuePair("rFlag", "1")); | |
| nvps.add(new BasicNameValuePair("startStation_ticketLeft", "北京")); | |
| nvps.add(new BasicNameValuePair("startStation_ticketLeft_new_value", "true")); | |
| nvps.add(new BasicNameValuePair("tFlagDC", "DC")); | |
| nvps.add(new BasicNameValuePair("tFlagK", "K")); | |
| nvps.add(new BasicNameValuePair("tFlagLK", "LK")); | |
| nvps.add(new BasicNameValuePair("tFlagPK", "PK")); | |
| nvps.add(new BasicNameValuePair("tFlagPKE", "PKE")); | |
| nvps.add(new BasicNameValuePair("tFlagT", "T")); | |
| nvps.add(new BasicNameValuePair("tFlagZ", "Z")); | |
| nvps.add(new BasicNameValuePair("trainCode", "")); | |
| nvps.add(new BasicNameValuePair("trainCode_new_value", "true")); | |
| httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); | |
| HttpResponse response = httpClient.execute(httpost); | |
| HttpEntity entity = response.getEntity(); | |
| System.out.println("Login form get: " + response.getStatusLine()); | |
| if (entity != null) { | |
| System.out.println(EntityUtils.toString(entity)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment