简体   繁体   English

使用cURL向tomcat localhost发出PHP请求并获得响应

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

I'm new to PHP and am currently struggling to set this up. 我是PHP的新手,目前正在努力进行设置。 Could someone provide me an outline of how you use curl to post and retrieve the returning data? 有人可以给我概述一下如何使用curl来发布和检索返回的数据吗?

I tried this out: 我尝试了这个:

$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);

But I keep getting the HTTP status 405 Error (aka this): 但是我一直收到HTTP状态405错误(又名这): 悲伤

Am I doing something wrong/what should I do? 我做错了什么/该怎么办? Or do I have to change something in my ds/stuff 还是我必须更改ds / stuff中的某些内容

You should set CURLOPT_POST to true . 您应该将CURLOPT_POSTtrue POST data goes to CURLOPT_POSTFIELDS . 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