• url传递数据


    一、post传递数据
    $ci = curl_init($url);
    curl_setopt($ci, CURLOPT_HEADER, 0);
    curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ci, CURLOPT_POST, 1);
    curl_setopt($ci,CURLOPT_POSTFIELDS,$data);
    $return = curl_exec($ci);
    echo $return;
    curl_close($ch);
    
    
    二、get传递数据
        $url="www.baidu.com?id=1";
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $response = curl_exec($ch);
            echo $response;

     三、post传递数据给java

    (一)单个键值对

     

            $url="www.baidu.com";
            $requestApi = curl_init();
            curl_setopt($requestApi, CURLOPT_URL, $url);
            curl_setopt($requestApi, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($requestApi, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($requestApi, CURLOPT_HEADER, 0); //将头文件的信息作为数据流输出
            $header[] = 'Content-type:application/x-www-form-urlencoded';
            curl_setopt($requestApi, CURLOPT_HTTPHEADER, $header);
            curl_setopt($requestApi, CURLOPT_POST, 1);
            $arr=array(
                'name'=>'huahua',
                'age'=>20
            );
            $data = http_build_query($arr);
            curl_setopt($requestApi, CURLOPT_POSTFIELDS, $data);
            curl_setopt($requestApi, CURLOPT_RETURNTRANSFER, 1); //返回获取的输出文本流
            $result = curl_exec($requestApi);
            curl_close($requestApi);

    (二)整个键值对

            $url="www.baidu.com";
            $requestApi = curl_init();
            curl_setopt($requestApi, CURLOPT_URL, $url);
            curl_setopt($requestApi, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($requestApi, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($requestApi, CURLOPT_HEADER, 0); //将头文件的信息作为数据流输出
            $header[] = 'Content-type:application/x-www-form-urlencoded';
            curl_setopt($requestApi, CURLOPT_HTTPHEADER, $header);
            curl_setopt($requestApi, CURLOPT_POST, 1);
            $arr=array(
                'name'=>'huahua',
                'age'=>20
            );
             $postData = [
                'postData' => json_encode($arr)
             ];
             $data = http_build_query($postData);
            curl_setopt($requestApi, CURLOPT_POSTFIELDS, $data);
            curl_setopt($requestApi, CURLOPT_RETURNTRANSFER, 1); //返回获取的输出文本流
            $result = curl_exec($requestApi);
            curl_close($requestApi);
  • 相关阅读:
    Swift 正式开源, 包括 Swift 核心库和包管理器
    Swift 3 新特性
    iOS10 CoreData新特性
    iOS各个版本的新特性介绍
    iOS WKWebView详解
    Swift XML解析库
    ios辅助功能之voiceover实战
    iOS 内存管理机制和循环引用处理方法
    Swift 关键字汇总
    Swift 自动布局框架-SnapKit
  • 原文地址:https://www.cnblogs.com/xiaobiaomei/p/7722953.html
Copyright © 2020-2023  润新知