Loading...

使用curl執行POST請求

Temperature: 0 °C

Mark ChangMark Chang
author_tools

curl命令是一個利用URL規則在命令行下工作的文件傳輸工具。

支持文件的上傳和下載。

這邊範例使用curl向遠端執行POST請求,並送出數據。

$value_a = "12345678";
$value_b = "test";

$url = "$url";//請求網址
$data = array(
"value_a " => $value_a ,
"value_b " => $value_b
);
$ch = curl_init();
$timeout = 30; 
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//Post提交數據包
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($result);  

以上紀錄
 

https://innstory.com/story-使用curl執行POST請求-1894
PHP

Prev
 javascript如何取得檔案的副檔名

Next
使用JavaScript的split函式完成字串切割 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

php在windows系統下無法使用mb_send_mail寄信?

php在windows系統下...

首先,mbsendmail是php所提供可用來發送編碼的郵件。 一般來說會導致無法發送郵件大部分原因...

文件上傳過程中使用白名單、黑名單、或者MIME做認證

文件上傳過程中使用白名單、黑...

pexelsphotolock5 是不是被資安的問題搞得很煩? 我想,在建置系統的過程中,或多或少都...

如何修復Undefined Index錯誤訊息

如何修復Undefined ...

錯誤的原因是因為當我們使用 $GET 和 $POST 方法取得變數時會發生這種情況,雖然PHP的部分...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format