Train ticket query interface demo and return sample code

Source: Internet
Author: User


Using system;


Using system. Collections. Generic;


Using system. LINQ;


Using system. text;


Using system. net. Security;


Using system. Security. cryptography. x509certificates;


Using system. net;


Using system. IO;


Using system. Io. compression;


Using system. Text. regularexpressions;


Using system. Web. Script. serialization;


Namespace trian ticket


{


Class Program


{


Static void main (string [] ARGs)


{


String key = "52bd00811f3442d8a6cca4ed61980000a"; // applied key value


String date = "2014-09-28"; // Date


String from = "Shanghai"; // name of the departure city

String to = "WenZhou"; // name of the target City


String url = "http://apis.haoservice.com/lifeservice/train/ypcx? Date = "+ date +" & from = "+ from +" & to = "+ to +" & Key = "+ key;


WebClient WC = new WebClient ();


WC. Encoding = encoding. utf8;


String STR = WC. downloadstring (URL );


Console. writeline (STR );


Console. readkey ();


}


}


}




Example of returning the year interface for querying train tickets


Interface Information


URL: http://apis.haoservice.com/lifeservice/train/ypcx


Supported format: JSON


HTTP Request Method: Get


Demo: http://apis.haoservice.com/lifeservice/train/ypcx? Date = & from = Shanghai & to = Wenzhou & Key = The appkey you applied


Returned results:

{

"Error_code": "0 ",

"Reason": "success ",

"Result ":[{

"Train_no": "d2287",/* trains *//

"Start_station_name": "Shanghai Hongqiao",/* train departure station */

"End_station_name": "Shenzhen north",/* Train Terminal */

"From_station_name": "Shanghai Hongqiao",/* departure site */

"To_station_name": "WenZhou South",/* arrival site */

"Start_time": "06:25",/* departure time */

"Arrive_time": "10:53",/* arrival time */

"Train_class_name": "",/* Train Type */

"Day_difference": "0",/* Days */

"Lishi": "",/* total duration */

"Gr_num": "--",/* High Level soft sleeper: -- indicates that this seat is not available */

"Qt_num": "--",/* Others */

"Rw_num": "--",/* Soft Sleeper */

"Rz_num": "--",/* soft seat */

"Tz_num": "--",/* special seat */

"Wz_num": "NONE",/* No seat */

"Yw_num": "--",/* hard sleeper */

"Yz_num": "--",/* hard seat */

"Ze_num": "NONE",/* second-class seat */

"Zy_num": "NONE",/* first-class seat */

"Swz_num": "--"/* business seat */

},

......

{

"Train_no": "g7501 ",

"Start_station_name": "Shanghai Hongqiao ",

"End_station_name": "Cangnan ",

"From_station_name": "Shanghai Hongqiao ",

"To_station_name": "WenZhou South ",

"Start_time": "07:00 ",

"Arrive_time": "11: 00 ",

"Train_class_name ":"",

"Day_difference": "0 ",

"Lishi": "4:00 ",

"Gr_num ":"--",

"Qt_num ":"--",

"Rw_num ":"--",

"Rz_num ":"--",

"Tz_num ":"--",

"Wz_num": "165 ",

"Yw_num ":"--",

"Yz_num ":"--",

"Ze_num": "NONE ",

"Zy_num": "NONE ",

"Swz_num": "15"

}]

}

Remarks

From now on to July 1, the Railway Department will adjust the train operation diagram. The train operation density, speed, and time of stopping nationwide will change.




Note:


Apply for the key value on the web page (http://www.haoservice.com/docs/25) First, fill in the parameters.


If any error occurs, refer to the code table below.


Error code table:


Return Code Description


0 successful


Request key with 10001 Error


10002 this key has no request permission


The 10003 key expires.


SDK key with 10004 Error


10005 application not reviewed timeout. Please submit for authentication


10007 unknown request source (the server has not obtained an IP address)


10008 forbidden IP Address


10009 forbidden key


10011 the current IP request exceeds the limit


10012 the current key request has exceeded the limit.


10013 the test key exceeds the request limit


10020 interface Maintenance


10021 disable the interface


10022 the number of requests remaining on demand for the appkey is zero.


10023 invalid request IP Address


10024 network errors


10025 no results found







Train ticket query interface demo and return sample code

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.