繁体   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