zoukankan      html  css  js  c++  java
  • PHPCURL直接访问JSONRPC服务

     1 <?php
     2 $ch = curl_init();
     3 $url = 'http://localhost/jsonrpc?tm='.time().mt_rand (100,999); //参数是为了防止缓存
     4 $options = array(
     5     CURLOPT_URL => $url,
     6     CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0",
     7     CURLOPT_RETURNTRANSFER => 1,  
     8     );
     9 curl_setopt_array($ch, $options);
    10 #JSON 示例数据
    11 curl_setopt($ch, CURLOPT_POSTFIELDS, '{"jsonrpc":"2.0","method":"getOpt","id":1}'); 
    12 
    13 $html=curl_exec($ch);
    14 $info = curl_getinfo($ch);            #获取请求的详细信息 用于调试
    15 curl_close($ch); 
    16 var_dump($html);

    注意CURLOPT_POSTFIELDS是不能http_build_query的,注意这点和普通的POST数据不一样,这里类似文件上传

  • 相关阅读:
    centos6.8升级python3.5.2
    钓鱼
    斯诺登的密码
    模板,堆,小根堆
    哥德巴赫猜想(升级版)
    哥德巴赫猜想
    线性筛素数
    乒乓球
    数的重心模板
    笨小猴
  • 原文地址:https://www.cnblogs.com/toumingbai/p/4010924.html
Copyright © 2011-2022 走看看