使用cURL向tomcatlocalhost发出PHP请求并获取响应

使用cURL向tomcatlocalhost发出PHP请求并获取响应,php,curl,Php,Curl,我是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)

我是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_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);

您应该将
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);

您应该将
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);

您应该将
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);

谢谢!:)附带问题:如果我想添加其他选项,如“text/text”和/或“UTF-8”,它是否会以$string形式出现?@hhyder这里是可用选项的完整列表:谢谢!:)附带问题:如果我想添加其他选项,如“text/text”和/或“UTF-8”,它是否会以$string形式出现?@hhyder这里是可用选项的完整列表:谢谢!:)附带问题:如果我想添加其他选项,如“text/text”和/或“UTF-8”,它是否会以$string形式出现?@hhyder这里是可用选项的完整列表:谢谢!:)附带问题:如果我想添加其他选项,如“text/text”和/或“UTF-8”,它是否会出现在$string中?@hhyder下面是可用选项的完整列表: