curl -H "token:您申请接口的token" -H "timestamp:1676766665" -H "sign:aedc77b7476278c8e780446ae4af6720" -H "content-type:application/json" -d {} http://i.zlapi.top/api/v1/normal/cangtoushi/query
<?php
$url = "http://i.zlapi.top/api/v1/normal/cangtoushi/query";
$params = [
];
$paramsStr = http_build_query($params);
$headers = [
"token" => "您申请接口的token",
"timestamp" => "1676766665",
"sign" => "aedc77b7476278c8e780446ae4af6720",
"content-type" => "application/json",
];
$content = httpRequest($url, $paramsStr,1,$headers);
$result = json_decode($content, true);
if ($result) {
var_dump($result);
} else {
}
function httpRequest($url, $dataStr = "", $isPost = 0,$headers=[])
{
$httpInfo = [];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/536.3");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (!empty($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
if ($isPost) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataStr);
curl_setopt($ch, CURLOPT_URL, $url);
} else {
curl_setopt($ch, CURLOPT_URL, $url . "?" . $dataStr);
}
$response = curl_exec($ch);
if ($response === false) {
return false;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$httpInfo = array_merge($httpInfo, curl_getinfo($ch));
curl_close($ch);
return $response;
}
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"strings"
"time"
)
func main() {
url := "http://i.zlapi.top/api/v1/normal/cangtoushi/query"
params := map[string]string{
}
headers := map[string]string{
"token":"您申请接口的token",
"timestamp":"1676766665",
"sign":"aedc77b7476278c8e780446ae4af6720",
"content-type":"application/json",
}
response, err := HttpRequest("POST", url, params, headers, 15)
if err != nil {
fmt.Println("请求异常:", err.Error())
} else {
fmt.Println("请求结果:", response)
}
}
func HttpRequest(method, rawUrl string, bodyMaps, headers map[string]string, timeout time.Duration) (result string, err error) {
var (
request *http.Request
response *http.Response
res []byte
)
if timeout <= 0 {
timeout = 5
}
client := &http.Client{
Timeout: timeout * time.Second,
}
data := url.Values{}
for key, value := range bodyMaps {
data.Set(key, value)
}
jsons := data.Encode()
if request, err = http.NewRequest(method, rawUrl, strings.NewReader(jsons)); err != nil {
return
}
if method == "GET" {
request.URL.RawQuery = jsons
}
for key, val := range headers {
request.Header.Set(key, val)
}
if response, err = client.Do(request); err != nil {
return "", err
}
defer response.Body.Close()
if res, err = io.ReadAll(response.Body); err != nil {
return "", err
}
return string(res), nil
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using Xfrog.Net;
using System.Diagnostics;
using System.Web;
namespace ConsoleAPI
{
class Program
{
static void Main(string[] args)
{
string url = "http://i.zlapi.top/api/v1/normal/cangtoushi/query";
var parameters = new Dictionary<string, string>();
string result = sendPost(url, parameters, "post");
JsonObject newObj = new JsonObject(result);
String errorCode = newObj["error_code"].Value;
if (errorCode == "0")
{
Debug.WriteLine("成功");
Debug.WriteLine(newObj);
}
else
{
Debug.WriteLine(newObj["error_code"].Value+":"+newObj["reason"].Value);
}
}
static string sendPost(string url, IDictionary<string, string> parameters, string method)
{
if (method.ToLower() == "post")
{
HttpWebRequest req = null;
HttpWebResponse rsp = null;
System.IO.Stream reqStream = null;
try
{
req = (HttpWebRequest)WebRequest.Create(url);
req.Method = method;
req.KeepAlive = false;
req.ProtocolVersion = HttpVersion.Version10;
req.Timeout = 60000;
req.Headers.Add("token" , "您申请接口的token");
req.Headers.Add("timestamp" , "1676766665");
req.Headers.Add("sign" , "aedc77b7476278c8e780446ae4af6720");
req.Headers.Add("content-type" , "application/json");
byte[] postData = Encoding.UTF8.GetBytes(BuildQuery(parameters, "utf8"));
reqStream = req.GetRequestStream();
reqStream.Write(postData, 0, postData.Length);
rsp = (HttpWebResponse)req.GetResponse();
Encoding encoding = Encoding.GetEncoding(rsp.CharacterSet);
return GetResponseAsString(rsp, encoding);
}
catch (Exception ex)
{
return ex.Message;
}
finally
{
if (reqStream != null) reqStream.Close();
if (rsp != null) rsp.Close();
}
}
else
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + "?" + BuildQuery(parameters, "utf8"));
request.Method = "GET";
request.ReadWriteTimeout = 5000;
request.ContentType = "text/html;charset=UTF-8";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd();
return retString;
}
}
static string BuildQuery(IDictionary<string, string> parameters, string encode)
{
StringBuilder postData = new StringBuilder();
bool hasParam = false;
IEnumerator<KeyValuePair<string, string>> dem = parameters.GetEnumerator();
while (dem.MoveNext())
{
string name = dem.Current.Key;
string value = dem.Current.Value;
if (!string.IsNullOrEmpty(name))
{
if (hasParam)
{
postData.Append("&");
}
postData.Append(name);
postData.Append("=");
if (encode == "gb2312")
{
postData.Append(HttpUtility.UrlEncode(value, Encoding.GetEncoding("gb2312")));
}
else if (encode == "utf8")
{
postData.Append(HttpUtility.UrlEncode(value, Encoding.UTF8));
}
else
{
postData.Append(value);
}
hasParam = true;
}
}
return postData.ToString();
}
static string GetResponseAsString(HttpWebResponse rsp, Encoding encoding)
{
System.IO.Stream stream = null;
StreamReader reader = null;
try
{
stream = rsp.GetResponseStream();
reader = new StreamReader(stream, encoding);
return reader.ReadToEnd();
}
finally
{
if (reader != null) reader.Close();
if (stream != null) stream.Close();
if (rsp != null) rsp.Close();
}
}
}
}
var request = require("request");
var querystring = require("querystring");
const options = {
url: "http://i.zlapi.top/api/v1/normal/cangtoushi/query",
method: "POST",
headers: {
"token" : "您申请接口的token",
"timestamp" : "1676766665",
"sign" : "aedc77b7476278c8e780446ae4af6720",
"content-type" : "application/json",
},
body: querystring.stringify({
})
};
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
} else {
console.log("请求异常");
}
});
import net.sf.json.JSONObject;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Map;
import java.util.HashMap;
public class ApiDemo {
public static void main(String[] args) {
String url = "http://i.zlapi.top/api/v1/normal/cangtoushi/query";
Map<String, String> params = new HashMap<String, String>();
String paramsStr = urlencode(params);
System.out.println(paramsStr);
String response = requestGet(url,paramsStr);
System.out.println(response);
try {
JSONObject jsonObject = JSONObject.fromObject(response);
System.out.println(jsonObject);
} catch (Exception e) {
e.printStackTrace();
}
}
public static String urlencode(Map<String, String> data) {
StringBuilder sb = new StringBuilder();
for (Map.Entry i : data.entrySet()) {
try {
sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue() + "", "UTF-8")).append("&");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return sb.toString();
}
public static String doPost(String httpUrl, String paramStr) {
HttpURLConnection connection = null;
InputStream inputStream = null;
OutputStream outputStream = null;
BufferedReader bufferedReader = null;
String result = null;
try {
URL url = new URL(httpUrl);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setConnectTimeout(15000);
connection.setReadTimeout(60000);
connection.setDoOutput(true);
connection.setRequestProperty("token", "您申请接口的token");
connection.setRequestProperty("timestamp", "1676766665");
connection.setRequestProperty("sign", "aedc77b7476278c8e780446ae4af6720");
connection.setRequestProperty("content-type", "application/json");
outputStream = connection.getOutputStream();
outputStream.write(paramStr.getBytes());
if (connection.getResponseCode() == 200) {
inputStream = connection.getInputStream();
bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
StringBuilder sbf = new StringBuilder();
String temp;
while ((temp = bufferedReader.readLine()) != null) {
sbf.append(temp);
sbf.append(System.getProperty("line.separator"));
}
result = sbf.toString();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != bufferedReader) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != outputStream) {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != inputStream) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (connection != null) {
connection.disconnect();
}
}
return result;
}
}