Use the http post request 12306 website interface to query the train request API

Source: Internet
Author: User

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

 

Related Article

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.