duanpu1963 2018-08-08 10:42
浏览 52
已采纳

卷曲从json设置cookie到标题

I have this

{
  "session":"59a28f4741b0800302147c4e8db00e5e",
  "id":"765611988531745",
  "rememberLogin":"76561198852231745||67b583c48e95a76fbcf7da254714e206"
}

how can I set this cookie to curl headers when i send the POST request?

  • 写回答

1条回答 默认 最新

  • dongshenyu4638 2018-08-08 11:30
    关注

    You can convert with a simple function Curl cookie is something like a=b; c=d; So you need to convert your json to that.

    function jsontocookie($json) {
        $ret = "";
        foreach(json_decode($json, true) as $key => $value){
            $ret .= $key."=".$value."; ";
        }
        return $ret;
    }
    

    And send with CURLOPT_COOKIE

    curl_setopt($ch, CURLOPT_COOKIE, jsontocookie($json));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决
  • ¥15 关于华为5g模块mh5000-31接线问题
  • ¥15 keil L6007U报错
  • ¥15 webapi 发布到iis后无法访问
  • ¥15 初学者如何快速上手学习stm32?