```
root@tr-desktop:/www/wwwroot# cat -n curl.php
1 'Alice',
8 // 'age' => 30,
9 // 'city' => 'New York'
10 //];
11 //
12 //// 将数组编码为JSON格式
13 //$jsonResponse = json_encode($data);
14 //
15 //// 检查编码是否成功
16 //if ($jsonResponse === false) {
17 // // 处理编码错误
18 // echo json_encode(['error' => 'Failed to encode JSON']);
19 //} else {
20 // // 返回JSON对象
21 // echo $jsonResponse;
22 //}
23 // 初始化cURL会话
24 $ch = curl_init();
25
26 // 设置请求的URL
27 curl_setopt($ch, CURLOPT_URL, "http://186.318.205.123/api/ec/dev/table/datas?dataKey=46f2ecae-3ab0-4d16-88c7¤t=1&sortParams=%5B%5D&");
28
29 // 设置为TRUE,返回结果而不是直接输出
30 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
31
32 // 设置POST请求
33 curl_setopt($ch, CURLOPT_POST, true);
34
35 // 设置POST数据
36 $postData = [
37 'dataKey' => '46f2ecae-3ab0-4d16-88c7',
38 'current' => 1,
39 'sortParams' => '%5B%5D&'
40 ];
41 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); // 使用http_build_query处理数据
42
43 // 设置请求头,包含cookie
44 $cookie = "JSESSIONID=aaaGi7ZnQ1puUa-r-IOez;ecology_JSessionid=aaaGi7ZnQ1puUa-r-IOez"; // 替换为你的cookie
45 curl_setopt($ch, CURLOPT_COOKIE, $cookie);
46
47 // 执行请求
48 $response = curl_exec($ch);
49
50 // 检查请求是否成功
51 if ($response === false) {
52 echo 'Curl error: ' . curl_error($ch);
53 } else {
54 // 获取HTTP响应状态码
55 $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
56 //echo "HTTP Code: $httpCode\n";
57 //echo 'Response: ' . $response;
58 echo $response;
59 //exit;
60 //$jsonObject = json_decode($response,false);
61 //print_r($jsonObject);
62 }
63
64 // 关闭cURL会话
65 curl_close($ch);
```