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();