简体   繁体   English

在 php 中使用 curl 对远程服务器进行真实的发布请求

[英]using curl in php for real post request to remote server

I have to automate uploading values to a remote server by php script.我必须通过 php 脚本自动将值上传到远程服务器。

The interface accepts only POST variables - NO GET variables.该接口仅接受 POST 变量 - 不接受 GET 变量。

Interface documentation (for form field names) looks like:接口文档(用于表单字段名称)如下所示:

iegUsername: your username
iegPassword: your password
iegImportFile: The UTF-8 encoded plain text import file. The file data may optionally be zipped.

This means i have to POST TWO VARIABLES and ONE FILE.这意味着我必须发布两个变量和一个文件。 I'm new in Curl therefore i started in PHP with this:我是 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);

Actually i don't have added file support.实际上我没有添加文件支持。

My Problem我的问题

In Browser dev tools i cannot see any POST only GET responses.在浏览器开发工具中,我看不到任何 POST only GET 响应。

I need a real POST with data in it not a urled GET one...我需要一个真正的 POST 数据,而不是一个 urled GET ......

Hopefully someone can give help.希望有人可以提供帮助。

okay, misunderstood of server side and client side.好吧,误解了服务器端和客户端。 Thought a response back to my location should result in a post response within dev tools of browser, this is not correct.认为对我的位置的响应应该会在浏览器的开发工具中产生一个发布响应,这是不正确的。

POST works. POST 有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM