Use http get request 12306 website interface to get the station name and station code

Source: Internet
Author: User

Open the link http://www.devapi.org/12306-Search-Train-Number.html drag to the bottom of this page to see the attachment:

Attachment

Train station code dictionary: station_name.js

The dictionary is saved in JS. The data structure is as follows:

?
1
VaR station_names = '@ bjb | Beijing North | VAP | beijingbei | bjb | 0 ';
The uppercase letter VAP is the station code.

An interface testing tool is provided to simulate http get/post. Click here to download

This attachment contains a JS file, which is the code of the national railway station name. My program below is to get the train station name and its code in this JS file. For example, "Beijing North" and "VAP" in station_names above ". The link address of this JS file is:

Http://dynamic.12306.cn/otsweb/js/common/station_name.js

Using http get requests, get indicates that the browser obtains data from the server. During this period, the browser does not send any data to the server. All data is reflected in the URL. Get is to get data from the server. On the client side, the get method submits data through the URL, and the data can be seen in the URL. For the get method, the server uses request. querystring to obtain the value of the variable. The data submitted in get mode can contain up to 1024 bytes. Security issues. When you use get, the parameters are displayed in the address bar, but not post. Therefore, if the data is Chinese and non-sensitive, use get.

The sample code for retrieving parsed data is as follows:

           string formUrl = "http://dynamic.12306.cn/otsweb/js/common/station_name.js";             CookieContainer cookieContainer = new CookieContainer();                                    HttpWebRequest request = WebRequest.Create(formUrl) as HttpWebRequest;                request.Method = "GET";                      request.KeepAlive = false;                     request.AllowAutoRedirect = true;                       request.ContentType = "application/x-www-form-urlencoded";                   request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";                     request.CookieContainer = cookieContainer;             HttpWebResponse SendSMSResponse = (HttpWebResponse)request.GetResponse();            StreamReader SendSMSResponseStream = new StreamReader(SendSMSResponse.GetResponseStream());            string strRespone = SendSMSResponseStream.ReadToEnd();             SendSMSResponse.Close();             SendSMSResponseStream.Close();            Console.WriteLine(strRespone);            Console.Read();

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.