dongxiao0449 2013-11-01 16:39
浏览 42

将标头传递给远程请求

I have an HTTP GET request in Wordpress that looks like this:

$remote = vip_safe_wp_remote_get($api_base . "get.json?genre=" . $genre, false, 1, 3)

works fine, but I now need to pass in a couple of headers that look like this:

apikey: [key]
authtoken: [token]

How can I pass these in? I've tried doing $headers = array() with the arguments passed in as key value pairs, but that returns an HTTP 503 error. The service works when I try to access it from the command line with cURL.

  • 写回答

1条回答 默认 最新

  • dongzi0602 2013-11-01 16:43
    关注

    Try this:

    $params = array('headers' => array(
        'apikey' => '[key]',
        'authtoken'=> '[token]'
    ));
    
    $remote = vip_safe_wp_remote_get(
        $api_base . "get.json?genre=" . $genre, false, 1, 3, 20, $params);
    

    See the reference of vip_safe_wp_remote_get: http://vip.wordpress.com/functions/vip_safe_wp_remote_get/

    According to the reference the last argument is a

    set other arguments to be passed to wp_remote_get()

    See the reference of wp_remote_get: http://codex.wordpress.org/Function_Reference/wp_remote_get

    评论

报告相同问题?

悬赏问题

  • ¥20 C# TCP服务端,客户端退出后,不断有数据进来
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?