[英]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);
我做錯了什么/該怎么辦? 還是我必須更改ds / stuff中的某些內容
您應該將CURLOPT_POST
為true
。 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.