curl -i -X POST 'http://apigateway.jianjiaoshuju.com/api/v_1/air.html' -H 'AppCode:你自己的AppCode' -H 'AppKey:你自己的AppKey' -H 'AppSecret:你自己的AppSecret' --data 'arrive_code=arrive_code&leave_code=leave_code&query_date=query_date'
public static void main(String[] args) {
String host = "http://apigateway.jianjiaoshuju.com";
String path = "/api/v_1/air.html";
String method = "POST";
String appcode = "你自己的AppCode";
String appKey = "你自己的AppKey";
String appSecret = "你自己的AppSecret";
Map headers = new HashMap();
headers.put("appcode",appcode);
headers.put("appKey",appKey);
headers.put("appSecret",appSecret);
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
Map querys = new HashMap();
Map bodys = new HashMap();
bodys.put("arrive_code", "arrive_code");
bodys.put("leave_code", "leave_code");
bodys.put("query_date", "query_date");
try {
/**
* 重要提示如下:
* HttpUtils请从
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
* 下载
*
* 相应的依赖请参照
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
*/
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
System.out.println(response.toString());
//获取response的body
//System.out.println(EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
e.printStackTrace();
}
}
//using System.IO;
//using System.Text;
//using System.Net;
//using System.Net.Security;
//using System.Security.Cryptography.X509Certificates;
private const String host = "http://apigateway.jianjiaoshuju.com";
private const String path = "/api/v_1/air.html";
private const String method = "POST";
private const String appcode = "你自己的AppCode";
private const String appKey = "你自己的AppKey";
private const String appSecret = "你自己的AppSecret";
static void Main(string[] args)
{
String querys = "";
String bodys = "arrive_code=arrive_code&leave_code=leave_code&query_date=query_date";
String url = host + path;
HttpWebRequest httpRequest = null;
HttpWebResponse httpResponse = null;
if (0 < querys.Length)
{
url = url + "?" + querys;
}
if (host.Contains("https://"))
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
}
else
{
httpRequest = (HttpWebRequest)WebRequest.Create(url);
}
httpRequest.Method = method;
httpRequest.Headers.Add("appcode",appcode);
httpRequest.Headers.Add("appKey",appKey);
httpRequest.Headers.Add("appSecret",appSecret);
//根据API的要求,定义相对应的Content-Type
httpRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
if (0 < bodys.Length)
{
byte[] data = Encoding.UTF8.GetBytes(bodys);
using (Stream stream = httpRequest.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
}
try
{
httpResponse = (HttpWebResponse)httpRequest.GetResponse();
}
catch (WebException ex)
{
httpResponse = (HttpWebResponse)ex.Response;
}
Console.WriteLine(httpResponse.StatusCode);
Console.WriteLine(httpResponse.Method);
Console.WriteLine(httpResponse.Headers);
Stream st = httpResponse.GetResponseStream();
StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("\n");
}
public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
<?php
$host = "http://apigateway.jianjiaoshuju.com";
$path = "/api/v_1/air.html";
$method = "POST";
$appcode = "你自己的AppCode";
$appKey = "你自己的AppKey";
$appSecret = "你自己的AppSecret";
$headers = array();
array_push($headers, "appcode:" . $appcode);
array_push($headers, "appKey:" . $appKey);
array_push($headers, "appSecret:" . $appSecret);
//根据API的要求,定义相对应的Content-Type
array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");
$querys = "";
$bodys = "arrive_code=arrive_code&leave_code=leave_code&query_date=query_date";
$url = $host . $path;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
echo curl_exec($curl);
?>
import urllib, urllib2, sys
host = 'http://apigateway.jianjiaoshuju.com'
path = '/api/v_1/air.html'
method = 'POST'
appcode = '你自己的AppCode'
appKey = '你自己的AppKey'
appSecret = '你自己的AppSecret'
querys = ''
bodys = {}
url = host + path
bodys['arrive_code'] = '''arrive_code'''
bodys['leave_code'] = '''leave_code'''
bodys['query_date'] = '''query_date'''
post_data = urllib.urlencode(bodys)
request = urllib2.Request(url, post_data)
request.add_header('appcode', appcode)
request.add_header('appKey', appKey)
request.add_header('appSecret', appSecret)
//根据API的要求,定义相对应的Content-Type
request.add_header('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
response = urllib2.urlopen(request)
content = response.read()
if (content):
print(content)
NSString *appcode = @"你自己的AppCode";
NSString *appKey = @"你自己的AppKey";
NSString *appSecret = @"你自己的AppSecret";
NSString *host = @"http://apigateway.jianjiaoshuju.com";
NSString *path = @"/api/v_1/air.html";
NSString *method = @"POST";
NSString *querys = @"";
NSString *url = [NSString stringWithFormat:@"%@%@%@", host, path , querys];
NSString *bodys = @"arrive_code=arrive_code&leave_code=leave_code&query_date=query_date";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString: url] cachePolicy:1 timeoutInterval: 5];
request.HTTPMethod = method;
[request addValue: [NSString stringWithFormat:appcode] forHTTPHeaderField: @"appcode"];
[request addValue: [NSString stringWithFormat:appKey] forHTTPHeaderField: @"appKey"];
[request addValue: [NSString stringWithFormat:appSecret] forHTTPHeaderField: @"appSecret"];
[request addValue: @"application/x-www-form-urlencoded; charset=UTF-8" forHTTPHeaderField: @"Content-Type"];
NSData *data = [bodys dataUsingEncoding: NSUTF8StringEncoding];
[request setHTTPBody: data];
NSURLSession *requestSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSURLSessionDataTask *task = [requestSession dataTaskWithRequest:request
completionHandler:^(NSData * _Nullable body , NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSLog(@"Response object: %@" , response);
NSString *bodyString = [[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding];
//打印应答中的body
NSLog(@"Response body: %@" , bodyString);
}];
[task resume];