CURL
curl -X POST
--header 'Content-Type:application/json'
--data '[
'key'=>'您的KEY',
'type'=>'fcl',
'pol'=>'CNSZN',
'pod'=>'CYLIM',
'shipowner'=>'MSC',
'page'=>1,
'limit'=>10,
]'
https://scan.5688.com.cn/api/awice_api/getOceanData
PHP
$data = [
'key' => '您的KEY',
'type'=>'fcl',
'pol'=>'CNSZN',
'pod'=>'CYLIM',
'shipowner'=>'MSC',
'page'=>1,
'limit'=>10,
];
// 初始化 cURL
$curl = curl_init();
// 設(shè)置 cURL 選項(xiàng)
curl_setopt($curl, CURLOPT_URL, 'https://scan.5688.com.cn/api/awice_api/getOceanData'); // 請求的 URL
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 返回響應(yīng)而不直接輸出
curl_setopt($curl, CURLOPT_POST, true); // 設(shè)置為 POST 請求
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); // 提交的數(shù)據(jù),轉(zhuǎn)為 JSON 格式
// 設(shè)置請求頭
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-Type: application/json'
]);
// 執(zhí)行 cURL 請求
$response = curl_exec($curl);
// 檢查是否發(fā)生錯(cuò)誤
if (curl_errno($curl)) {
$error_msg = curl_error($curl);
echo 'Curl error: ' . $error_msg;
} else {
// 處理響應(yīng),根據(jù)需要解析 JSON
$responseData = json_decode($response, true);
print_r($responseData); // 打印響應(yīng)數(shù)據(jù),或進(jìn)行進(jìn)一步處理
}
// 關(guān)閉 cURL 會(huì)話
curl_close($curl);
JAVA
import java.io.BufferedReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import org.json.JSONObject; // 確保添加 JSON 庫依賴
public class Main {
public static void main(String[] args) {
try {
// 創(chuàng)建請求數(shù)據(jù)
JSONObject data = new JSONObject();
data.put("key", "您的KEY");
data.put("type", "fcl");
data.put("pol", "CNSZN");
data.put("pod", "CYLIM");
data.put("shipowner", "MSC");
data.put("page", "1");
data.put("limit", "10");
// 創(chuàng)建 URL 對象
URL url = new URL("https://scan.5688.com.cn/api/awice_api/getOceanData");
// 創(chuàng)建 HttpURLConnection 對象
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST"); // 設(shè)置請求方法為 POST
connection.setDoOutput(true); // 允許輸出
connection.setRequestProperty("Content-Type", "application/json"); // 設(shè)置請求頭
// 發(fā)送請求數(shù)據(jù)
try (OutputStream os = connection.getOutputStream()) {
byte[] input = data.toString().getBytes("utf-8");
os.write(input, 0, input.length);
}
// 獲取響應(yīng)碼
int responseCode = connection.getResponseCode();
System.out.println("Response Code: " + responseCode);
// 讀取響應(yīng)
try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"))) {
StringBuilder response = new StringBuilder();
String responseLine;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
// 輸出響應(yīng)內(nèi)容
System.out.println("Response Body: " + response.toString());
}
} catch (Exception e) {
e.printStackTrace(); // 打印異常
}
}
}
NODEJS
const axios = require('axios');
const fetchData = async () => {
try {
const data = {
key: '您的KEY',
type: 'fcl',
pol: 'CNSZN',
pod: 'CYLIM',
shipowner: 'MSC',
page: 1,
limit: 10,
};
const response = await axios.post('https://scan.5688.com.cn/api/awice_api/getOceanData', data, {
headers: {
'Content-Type': 'application/json',
},
});
console.log('Response Status:', response.status);
console.log('Response Data:', response.data);
} catch (error) {
console.error('Error:', error.message);
}
};
fetchData();