请求示例

您可以参阅API接口文档调整以下示例的代码。

PHP示例

点此下载该示例.php
<?php
    $host = "http://api.ip5i.com:800";
    $path = "/LotteryAPI.php";
    $method = "GET";
    $headers = array();
    $querys = "api=xy28&user=122474363&token=f980d8481d0ff9b9d66b5c1f5b7c4555&num=50";
    $bodys = "";
    $url = $host . $path . "?" . $querys;
    $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, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    var_dump(curl_exec($curl));
?>

C#示例

点此下载该示例.txt
//using System.Net.Security;
//using System.Security.Cryptography.X509Certificates;
 
        private const String host = "http://api.ip5i.com:800";
        private const String path = "/LotteryAPI.php";
        private const String method = "GET";
 
        static void Main(string[] args)
        {
            String querys = "api=xy28&user=122474363&token=f980d8481d0ff9b9d66b5c1f5b7c4555&num=50";
            String bodys = "";
            String url = host + path;
            HttpWebRequest httpRequest = null;
            HttpWebResponse httpResponse = null;
 
            if (0 < querys.Length)
            {
                url = url + "?" + querys;
            }
 
            if (host.Contains("http://"))
            {
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
            }
            else
            {
                httpRequest = (HttpWebRequest)WebRequest.Create(url);
            }
            httpRequest.Method = method;
            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;
        }

java示例

点此下载该示例.txt
	public static void main(String[] args) {
	    String host = "http://api.ip5i.com:800";
	    String path = "/LotteryAPI.php";
	    String method = "GET";
	    Map<String, String> headers = new HashMap<String, String>();
	    Map<String, String> querys = new HashMap<String, String>();
	    querys.put("api", "bkklb");
	    querys.put("user", "122474363");
	    querys.put("token", "f980d8481d0ff9b9d66b5c1f5b7c4555");
	    querys.put("num", "50");
	    try {
	    	HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
	    	System.out.println(response.toString());
	    	//获取response的body
	    	//System.out.println(EntityUtils.toString(response.getEntity()));
	    } catch (Exception e) {
	    	e.printStackTrace();
	    }
	}

curl示例

点此下载该示例.txt
curl -d "api=xy28&user=122474363&token=f980d8481d0ff9b9d66b5c1f5b7c4555&num=50" "http://api.ip5i.com:800/LotteryAPI.php"
工具

本站首页

友情链接

最近更改

媒体管理

网站地图


鄂ICP备16006029号
QR Code
QR Code svlikapi:请求示例 (generated for current page)