php 链接请求,php请求https接口

php请求https接口

2018-09-19

1。输入接口:

https://CRMC URL/ spservice/downring.do? sid =1234 & sidpwd =123456& randomsessionkey =123420031212121212123456& modulecode=z1000XXX&opertype=1&tonecode=1234123412& issendsms =0& backurl=

2。如何发送http请求,最好有例子,谢谢!

PHP的文件操作函数几乎都能用来发送http请求:

$html = file_get_contents("http://ww.google.com");

var_dump($html);

有些网站会对请求头信息进行检测,这时候就需要用到curl了(php.ini中要启用curl扩展),贴一个我一直用的函数:

function fetch_page($site,$url,$params=false)

{

$ch = curl_init();

$cookieFile = $site . "_cookiejar.txt";

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);

curl_setopt($ch, CURLOPT_COOKIEFILE,$cookieFile);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch,   CURLOPT_SSL_VERIFYPEER,   FALSE);

curl_setopt($ch, CURLOPT_HTTPGET, true);

curl_setopt($ch, CURLOPT_TIMEOUT, 4);

if($params)

curl_setopt($ch, CURLOPT_POSTFIELDS, $params);

curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3");

curl_setopt($ch, CURLOPT_URL,$url);

$result = curl_exec($ch);

//file_put_contents("jobs.html",$result);

return $result;

}

调用示例:

$html = fetch_page("google","http://googlel.com","key=value");

var_dump($html);

如果请求类型是https,则只能用curl了,前者会报(至少默认情况下):

PHP Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?

如果你说的实现https接口指的是让别人可以用https访问你,那么就需要用openssl生成公私钥,然后编译apache使支持mod_ssl,然后再配置httpd-ssl.conf文件,这些让系统管理员来做吧。。

<

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。

http://www.pinlue.com/style/images/nopic.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值