PHP CURL PUT函数不起作用 [英] PHP CURL PUT function not working

查看:181
本文介绍了PHP CURL PUT函数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向不起作用的java服务发出put请求,即使它也没有显示任何描述性错误。

I want to issue a put request to a java service where it's not working, even its not showing any descriptive errors as well.

include './rootURL.php';

$header = array("Content-Type: application/json");

$prop_key = 'prop key value';

$data = array();
$data = json_decode(file_get_contents('php://input'), true);
$id = $data["id"];

$url = $rooturl.'cancelBooking/'.$prop_key.'/'.$id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_TIMEOUT, 75);
$result = curl_exec($ch);

error_log($result);            
echo $result;

上面是我的PHP脚本,URL听到了我想要的方式,我不不要认为URL中有任何错误。服务也可以正常工作,我用招摇和它的正常工作对其进行了测试。

the above is my php script and the URL hear is working the way i want it, i don't think there is anything wrong in the URL. services also working fine i tested it with swagger and its working fine.

当我记录错误时,我收到了类似的东西。

When i log the error, i received something like this.

[Thu Jun 02 12:56:38.813140 2016] [:error] [pid 6290] [client127.0.0.1:39198] , referer: http://localhost/adminPanel/booking.php


推荐答案

不要将您的数据放在任何地方。

It looks like you're not putting your data anywhere.

我有一项服务允许将数据放入,此代码就是我使用的代码

I have a service which allows to put data and this code is the one I use

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$return = curl_exec($ch);

此行 curl_setopt($ ch,CURLOPT_POSTFIELDS,http_build_query($ data)) ; 包含我提交的数据,但在您的代码中找不到此行。

This line curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); contains my data I submit but I can't find this line in your code.

再次检查您的代码并发现 $ prop_key ='prop键值'; 您在URL $ url = $ rooturl.'cancelBooking /'.$ prop_key。'/'中使用。 $ id;

Checked your code again and found $prop_key = 'prop key value'; which you're using in the URL $url = $rooturl.'cancelBooking/'.$prop_key.'/'.$id;

将网址更改为 $ url = $ rooturl.'cancelBooking /'。urlencode($ prop_key )。'/'。$ id;
,因为空格可能是个问题。

Change the url to $url = $rooturl.'cancelBooking/'.urlencode($prop_key).'/'.$id; since the whitespaces might be a problem.

这篇关于PHP CURL PUT函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆