簡體   English   中英

使用cURL向tomcat localhost發出PHP請求並獲得響應

[英]Make PHP Request to tomcat localhost using cURL and get response

我是PHP的新手,目前正在努力進行設置。 有人可以給我概述一下如何使用curl來發布和檢索返回的數據嗎?

我嘗試了這個:

$url = 'http://localhost:8080/ds/stuff?maybe=false';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, $string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

但是我一直收到HTTP狀態405錯誤(又名這): 悲傷

我做錯了什么/該怎么辦? 還是我必須更改ds / stuff中的某些內容

您應該將CURLOPT_POSTtrue POST數據進入CURLOPT_POSTFIELDS

$url = 'http://localhost:8080/ds/stuff?maybe=false';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

暫無
暫無

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

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