本站资源收集于互联网,不提供软件存储服务,每天免费更新优质的软件以及学习资源!

Postman调用本地PHPAPI时_为何找不到$

网络教程 app 1℃

Postman调用本地PHPAPI时_为何找不到$

postman 调用 localhost php api 时为何找不到 $_server[‘http_origin’]?

postman 调用本地 php api 时出现“notice: undefined index: http_origin”错误,是因为 origin 头是浏览器 cors 中用来区分请求来源的,而其他环境不受其限制。

postman 模拟 http_origin

要模拟 origin 头,在 postman 的 headers 标签中添加一个名为 origin 的自定义头,并将值设置为网站的 url(格式为 ://[:

])。例如,对于 example.,origin 值应为 example.。

注意

由于不是所有用户代理都会发送 origin 头,因此在 php 中应使用 isset() 或 ?? 操作符检查其是否存在后再取用。例如:

$origin = $_server[‘http_origin’] ?? ”;

$origin = ”;if (isset($_SERVER[‘HTTP_ORIGIN’])) { $origin = $_SERVER[‘HTTP_ORIGIN’];}

以上就是Postman 调用本地 PHP API 时,为何找不到 $_SERVER[‘HTTP_ORIGIN’]?的详细内容,更多请关注范的资源库其它相关文章!

转载请注明:范的资源库 » Postman调用本地PHPAPI时_为何找不到$

喜欢 (0)