PHP中HTTPRequest的替代方法

编程入门 行业动态 更新时间:2024-10-26 03:40:11
本文介绍了PHP中HTTPRequest的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在php脚本中使用HttpRequest类,但是当我将此脚本上传到托管提供商的服务器时,执行该脚本时会出现致命错误:

I am using the HttpRequest class in my php script, but when I uploaded this script to my hosting provider's server, I get a fatal error when executing it:

致命错误:在第87行的...中找不到类'HttpRequest'

Fatal error: Class 'HttpRequest' not found in ... on line 87

我相信原因是因为我的托管服务提供商的php.ini配置不包括支持HttpRequest的扩展.当我联系他们时,他们说我们不能在共享主机上安装以下扩展.所以我想要这样的httpRequest替代项:

I believe the reason is because my hosting provider's php.ini configuration doesnt include the extension that supports HttpRequest. When i contacted them they said that we cannot install the following extentions on shared hosting. So i want the alternative for httpRequest which i make like this:

$url= ip:8080/folder/SuspendSubscriber?subscriberId=5 $data_string=""; $request = new HTTPRequest($url, HTTP_METH_POST); $request->setRawPostData($data_string); $request->send(); $response = $request->getResponseBody(); $response= json_decode($response, true); return $response;

或者我该如何在curl中使用此请求,因为它不适用于空数据串?

Or How can i use this request in curl as it is not working for empty datastring?

推荐答案

您可以像这样在php中使用CURL:

You can use CURL in php like this:

$ch = curl_init( $url ); $data_string = " "; curl_setopt( $ch, CURLOPT_POSTFIELDS, $data_string ); curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); $result = curl_exec($ch); curl_close($ch); return $result;

和空的数据字符串在发布请求中没有意义,但是我已经用空的数据字符串检查了它,并且运行得很好.

and empty data string doesn't make sense in post request, but i've checked it with empty data string and it works quiet well.

更多推荐

PHP中HTTPRequest的替代方法

本文发布于:2023-11-15 17:27:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1596494.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   PHP   HTTPRequest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!