zoukankan      html  css  js  c++  java
  • php curl 上传json数据

    PUT

    $data = array('username'=>'dog','password'=>'tall');
    $data_json = json_encode($data);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_json)));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);
    POST

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);
    GET See @Dan H answer

    DELETE

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);

  • 相关阅读:
    中文和英文
    文件字符流
    Java IO File
    关于整数拆分的递归法与母函数法
    图论·Dijkstra·HDU2066
    图论·Floyd算法·HDU2544&1874 (伪)2066
    关于 图论·并查集·HDU1232&1856
    Power of Cryptography
    Y2K Accounting Bug
    整数划分
  • 原文地址:https://www.cnblogs.com/cosiray/p/7762719.html
Copyright © 2011-2022 走看看