Use the interface provided by the 12306 website to pass in parameters and parse data. First, let's take a look at the link...
Http://www.devapi.org/12306-Search-Train-Number.html
Interface Type:
HTTP (POST)/UTF-8
Interface return value:
Json
Parameters:
Method = queryststrainall
Constant, indicating the number of trains to query. (This parameter is the get parameter)
Date = 2013-1-1 1-1
Specifies the date to be queried.
Fromstation = BJP
The START Station Code. For the code dictionary of all stations, see the appendix "station_name.js ".
Tostation = SHH
Terminal code, same as above.
Starttim = 00:00 -- 24:00
Specify the travel time range.
Enumeration: 00: 00--24: 00,00: 00--06: 00,06: 00--12: 00,12: 00--18: 00,18: 00--24: 00.
HTTP defines different methods for interaction with the server. The most basic methods are GET and POST. Retained POST is only used for site update. POST indicates a request that may change resources on the server. Each HTTP-GET and HTTP-POST consists of an HTTP request header that defines what the client requests from the server. Like a HTTP-GET, HTTP-POST parameters are URL encoded. However, the variable name/variable value is not transmitted as part of the URL, but is transmitted within the actual HTTP request message. POST is another way to retrieve data, but at the beginning of the request, the browser needs to send additional data to the server, such as cookies, usernames, passwords, and so on, the data is not reflected in the URL. After sending the data, the server sends the data (webpage) to the browser.
The http post request is used to send the URL and DATA. The 12306API accepts the request, parses the request, and returns the corresponding request DATA. For example:
URL: http://dynamic.12306.cn/otsquery/query/queryRemanentTicketAction.do? Method = queryststrainall
Data: date = 2013-1-1 & fromstation = BJP & tostation = SHH & starttime = 00:00 -- 24:00
CoontentType: application/x-www-form-urlencoded
When Data is transmitted, there are four parameters: date is the date, fromstation is the origin site, tostation is the terminal, and starttime is the time. In short, the Data of the Data Request returns all the train information of the departure station and the terminal station during this date period. The sample code is as follows:
Main( formUrl = formData = = [] postData = HttpWebRequest request = WebRequest.Create(formUrl) = Encoding.GetEncoding(= = = = === System.IO.Stream outputStream == request.GetResponse() == =