首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何捕获来自另一个web服务的POST请求

如何捕获来自另一个web服务的POST请求
EN

Stack Overflow用户
提问于 2018-01-30 20:26:55
回答 1查看 196关注 0票数 0

我正在使用Block.io Web Hooks。它说通知服务需要通过POST请求进行通信。它还声明所有通知事件都将使用以下JSON对象结构:

代码语言:javascript
运行
复制
{ 
  "notification_id" : "...", // a unique identifier issued when you created the notification
  "delivery_attempt" : 1, // number of times we've tried deliverying this object
  "type" : "...", // the type of notification, helps you understand the data sent below
  "data" : {
    ... // the notification data
  },
  "created_at" : 1426104819 // timestamp of when we created this notification
}

我已经提供了我的回调URL,我看到有行插入到我的数据库中,但是值是空的。是的,我知道我的代码将插入空白,但当我触发API时,它也是插入空白。

代码语言:javascript
运行
复制
<?php
$post = '';

foreach($_POST as $k => $v){
    $post .= $k.'='.$v.'&';
}

// save data into database
?>
EN

回答 1

Stack Overflow用户

发布于 2018-01-30 20:37:19

webhook返回json,PHP不会将其解析为$_POST数组。

相反,您需要从以下位置获取字符串:

代码语言:javascript
运行
复制
file_get_contents('php://input')

这是你可以自己解析的。要获取数组,请执行以下操作:

代码语言:javascript
运行
复制
$array = json_decode(file_get_contents('php://input'), true);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48521476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档