【发布时间】:2019-12-03 04:57:46
【问题描述】:
我必须通过 php 脚本自动将值上传到远程服务器。
接口只接受 POST 变量 - 不接受 GET 变量。
接口文档(用于表单字段名称)如下所示:
iegUsername: your username
iegPassword: your password
iegImportFile: The UTF-8 encoded plain text import file. The file data may optionally be zipped.
这意味着我必须发布两个变量和一个文件。 我是 Curl 的新手,因此我开始使用 PHP:
// create curl resource
$request = curl_init();
// Array with the fields names and values
$postData = array(
'iegUsername' => 'myusername',
'iegPassword' => 'mypassword',
'submit' => 'ok'
);
//add file support with: 'file' => '@' . realpath('example.txt')
// set timeout if remote server is down
curl_setopt($request, CURLOPT_CONNECTTIMEOUT, 30);
// set remote target url
curl_setopt($request, CURLOPT_URL, ""); //for testing post on current page
//Enable the post response.
//curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "POST");
$headers = ['Content-Type: multipart/form-data'];
curl_setopt($request, CURLOPT_HTTPHEADER, $headers);
//The data to transfer with the response.
curl_setopt($request, CURLOPT_POSTFIELDS, $postData);
//return the transfer as a string
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
// disable verification
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($request, CURLOPT_SSL_VERIFYHOST, false);
实际上我没有添加文件支持。
我的问题
在浏览器开发工具中,我看不到任何仅 POST GET 响应。
我需要一个真正的 POST,其中包含数据,而不是 URL GET ......
希望有人可以提供帮助。
【问题讨论】:
-
您没有看到 POST 请求,因为该请求是在服务器端完成的,而您的浏览器开发工具只能看到客户端请求。
-
好啊!如何调试我的变量?
-
用 print_r(curl_getinfo($request));我看不到变量。