douqi3064 2014-06-25 10:49
浏览 26
已采纳

curl命令到php

I want to use this curl command (works with Windows curl)

curl -k -i -H "Accept: application/json" https://brackets-registry.aboutweb.com/registryList 

inside php curl. I tried this code:

<?php
 $url="https://brackets-registry.aboutweb.com/registryList";

 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-type: application/json']);


 $result = curl_exec($ch);
 curl_close($ch);

 var_dump($result);

But I don't get any json only html source code. I think I am using the -H and the -k option, right? Don't know how to add -i.

  • 写回答

3条回答 默认 最新

  • duanchao5258 2014-06-25 11:01
    关注

    Why don't you use a library such as Guzzle to connect to the api?

    In your command line, you use the Accept HTTP header, which negociate the content type of the response, but in your curl option you are using Content-Type, saying any information in your request body is in JSON, nothing about the response type you want. I therefore would have an extra line such as:

    curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept: application/json']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥40 selenium访问信用中国
  • ¥15 电视大赛投票系统的c语言代码怎么做
  • ¥20 在搭建fabric网络过程中遇到“无法使用新的生命周期”的报错
  • ¥15 Python中关于代码运行报错的问题
  • ¥500 python 的API,有酬谢
  • ¥15 软件冲突问题,软件残留问题
  • ¥30 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥50 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥15 alpha101因子里哪些适合crypto?
  • ¥15 ctrl win alt 键一直触发
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部