我使用file_get_contents函数来获取和显示我的特定页面上的外部链接.
在我的本地文件中一切正常,但我的服务器不支持该file_get_contents功能,所以我尝试使用以下代码的cURL:
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
echo file_get_contents_curl('http://google.com');
Run Code Online (Sandbox Code Playgroud)
但它返回一个空白页面.怎么了?
假设我在某个服务器上运行RESTful API,以及一个单独但相关的Wordpress站点.
我希望WP站点上有一些页面显示从REST服务器检索的WP页面上的数据(采用JSON格式),并允许用户查看和/或编辑WP页面上的数据.
例如,假设我有一个返回用户拥有的书籍列表的API作为REST起点.我想显示书籍列表,允许用户点击书籍链接并转到显示书籍详细信息的页面.
然后,如果用户进入"编辑模式",则允许他/她编辑数据并通过REST API将其POST/PUT返回服务器.
有没有WP插件可以让我创建显示和编辑这样的信息的页面?
我希望对于每种类型的实体,我都可以输入一些元数据来指示JSON中的内容,以及如何显示它以供查看或如何为其构建表单(如iPhorms所做的那样).
在PHP中使用file_get_contents或curl应该使用哪个来发出HTTP请求?
如果file_get_contents能完成这项工作,是否需要使用curl?使用curl似乎需要更多的线条.
例如:
卷曲:
$ch = curl_init('http://www.website.com/myfile.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
curl_close ($ch);
Run Code Online (Sandbox Code Playgroud)
的file_get_contents:
$output = file_get_contents('http://www.website.com/myfile.php'.$content);
Run Code Online (Sandbox Code Playgroud) 我正在尝试显示来自 guzzle 请求的图像,一切正常,但我无法显示图像。
这是我在尝试获取用户数据时得到的结果
object(GuzzleHttp\Psr7\Response)#427 (6) { ["reasonPhrase":"GuzzleHttp\Psr7\Response":private]=> string(2) "OK" ["statusCode":"GuzzleHttp\Psr7\Response":private]=> int(200) ["headers":"GuzzleHttp\Psr7\Response":private]=> array(14) { ["Server"]=> array(1) { [0]=> string(6) "Cowboy" } ["Connection"]=> array(1) { [0]=> string(10) "keep-alive" } ["X-Powered-By"]=> array(1) { [0]=> string(7) "Express" } ["X-Timestamp"]=> array(1) { [0]=> string(13) "1556374181931" } ["Content-Disposition"]=> array(1) { [0]=> string(51) "attachment; filename =profile_img-1556366764744.jpg" } ["X-Sent"]=> array(1) { [0]=> string(4) "true" } ["Accept-Ranges"]=> array(1) { [0]=> string(5) "bytes" } ["Cache-Control"]=> array(1) { [0]=> string(17) "public, max-age=0" } ["Last-Modified"]=> array(1) { [0]=> string(29) "Sat, …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我将使用 connectwise API,但我不知道如何调用它们的 API,例如
在此先感谢您的帮助!!