我正在尝试用asp.net mvc api编写一个web钩子接收器。
但问题是,webhook初始化应用程序需要一种奇怪的验证方法。他们需要我添加以下代码来验证,并允许我在仪表板中添加我的URL。
`<?php if (isset($_GET['zd_echo'])) exit($_GET['zd_echo']); ?>`你认为我能在asp.net上实现什么呢?到目前为止我一直在跟踪。(它在邮递员中有效,但他们无法证实。)
// POST api/<controller>
public string Post([FromBody]CallNotification value, string zd_echo)
{
if( zd_echo != null && zd_echo != "")
{
return value.zd_echo;
}
else
{
this.AddCall(value);
return value.status_code;
}
}

发布于 2019-02-16 04:54:09
首先,我不是Php开发人员。第二,这里有很多假设,所以这完全是基于你发布的内容。
<?php if (isset($_GET['zd_echo'])) exit($_GET['zd_echo']); ?> HTTP GET变量是来自query string的$_GET变量。所以这是一个GET请求与您的API的预期POSTquery string中回显query string键的值,例如,如果设置为 isset,http://example.com/?zd_echo=foo将回显/响应foo
根据上述假设:
// Just echo the value of the zd_echo key in the query string if it's set
public IHttpActionResult Get([FromUri] string zd_echo)
{
//if not set/null return HTTP 200
if (string.IsNullOrWhiteSpace(zd_echo))
return Ok();
return ResponseMessage(new HttpResponseMessage
{
Content = new StringContent(zd_echo)
});
}因此,请求:http://example.com/api/webhook?zd_echo=bar将:
bar回复,Content-Type: text/plain; charset=utf-8否则,像http://example.com/api/webhook?zd_echo这样的东西只会用HTTP/1.1 200 OK响应
Hth。
https://stackoverflow.com/questions/54715507
复制相似问题