WordPress教程

wp_remote_get 发送 GET 请求到 URL 并返回数据

阿里云

使用 GET 方法执行 HTTP 请求并返回其响应。

参数 数据类型 是否必需 描述 默认值
$url 字符串 请求 URL
$args 数组 请求参数 array()

函数返回值

成功时,返回一个数组,失败时,返回一个 WP_Error 对象

也想出现在这里?联系我们
创客主机

使用示例

发送 HTTP 请求时,我们可以通过该函数的 $args 参数来设置 HTTP 的各种参数,包括超时时间,HTTP 版本,Headers 等信息。

请求时设置超时时间和 HTTP 版本。

  1. $response = wp_remote_get( 'http://www.example.com/index.php?action=foo',
  2.     array(
  3.         'timeout'     => 120,
  4.         'httpversion' => '1.1',
  5.     )
  6. );

请求时设置内容类型和 API Key。

  1. $args = array(
  2.     'headers' => array(
  3.         'Content-Type' => 'application/json',
  4.         'X-Api-Key' => 'apikey12345'
  5.     )
  6. )
  7.  
  8. $response = wp_remote_get( $url, $args );
WordPress程序远程数据请求函数:wp_remote_post、wp_remote_get 发起 HTTP 请求,是再平常不过的需求了。一般的就是使用 file_get_contents 或者 cURL […]
日期:2022/9/14 阅读:642阅读全文

wp_remote_get 发送 GET 请求到 URL 并返回数据

已有 104 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!