如何在没有http:// www前缀的情况下使用cURL [英] How To Use cURL without http://www Prefix

查看:160
本文介绍了如何在没有http:// www前缀的情况下使用cURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题。我想通过我的bulksms网关向我提供api链接,以便在我正在构建的网站中使用。链接是smsplus4.routesms.com。如果您使用www或 http:// www 前缀访问此链接,则此链接不起作用。现在我有卷曲功能

  function curl_get_contents($ url)
{
$ ch = curl_init( $网址);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ ch,CURLOPT_SSL_VERIFYHOST,0);
$ data = curl_exec($ ch);
curl_close($ ch);
返回$ data;
}
$ api =smsplus4.routesms.com;
curl_get_contents($ api);

由于缺少 http:// www 前缀。请问我该怎么办?如果没有 http:// www 前缀,我如何让cURL为我工作?
提前致谢。

解决方案

完全按照上面的代码运行似乎对我有用。

  $ cat test.php 
<?php

function curl_get_contents($ url)
{
$ ch = curl_init($ url);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ ch,CURLOPT_SSL_VERIFYHOST,0);
$ data = curl_exec($ ch);
curl_close($ ch);
返回$ data;
}
$ api =smsplus4.routesms.com;
echo curl_get_contents($ api); < - 添加echo以查看输出

?>
$ php test.php | head


<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD /xhtml1-transitional.dtd\">
< html xmlns =http://www.w3.org/1999/xhtml>
<! - <![endif] - >
<! - BEGIN HEAD - >
< head>
< meta charset =utf-8/>
< title> SmsPlus :: Login< / title>
< meta http-equiv =X-UA-Compatiblecontent =IE = edge>


i have this problem. I neent to cURL an api link given to me by my bulksms gateway for use in the site i'm building. The link is smsplus4.routesms.com . This link does not work if you access it with the www or http://www prefixes. Now i have the curl function

function curl_get_contents($url)
{   
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$api = "smsplus4.routesms.com";
curl_get_contents($api);

which did not work because of the missing http://www prefix. Pls what do i do? how do i get the cURL to work for me without the http://www prefix? Thanks in advance.

解决方案

Running exactly the code above seems to work for me.

$ cat test.php
<?php

function curl_get_contents($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$api = "smsplus4.routesms.com";
echo curl_get_contents($api);  <-- Added echo to see the output

?>
$ php test.php | head


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <!--<![endif]-->
    <!-- BEGIN HEAD -->
    <head>
        <meta charset="utf-8"/>
        <title>SmsPlus :: Login </title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">

这篇关于如何在没有http:// www前缀的情况下使用cURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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