簡體   English   中英

在 php 中使用 curl 對遠程服務器進行真實的發布請求

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

我必須通過 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 only GET 響應。

我需要一個真正的 POST 數據,而不是一個 urled GET ......

希望有人可以提供幫助。

好吧,誤解了服務器端和客戶端。 認為對我的位置的響應應該會在瀏覽器的開發工具中產生一個發布響應,這是不正確的。

POST 有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM