-2

尝试通过 C# RESTful 服务接收 COSM Trigger HTTP Post,但未收到警报。我从一个测试客户端获取了 COSM API JSON 有效负载并使用它——这很有效。当我设置我的提要并尝试调试触发器测试,或者只是强制触发器正常触发时,我的 REST 服务不会被调用。如果我尝试任何形式的测试客户端,服务处理 JSON POST 就好了。

C# 服务在这里:

    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "cosm", 
        RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    string CosmAlert(CosmTrigger data);

其中 CosmTrigger 是我的班级镜像COSM 触发器字段

我的 COSM 提要在这里

我从 COSM 门户开始触发触发器,基于 Twitter 的触发器工作正常,到我的 URL 的 HTTP Post 不是。如何调试这个?

4

2 回答 2

1

Cosm 触发器当前不将触发器作为 JSON 主体发送,它实际上发送一个 URL 编码请求,并将 JSON 触发器主体编码为称为“body”的参数。

在测试触发器上使用http://requestb.in,并查看原始输出,这显示基本请求如下所示:

POST /103s0dh1 HTTP/1.1
X-Request-Id: e05e9d699edbd5f584fc491cf9416df747be4df4
User-Agent: Cosm Deliverator (Axino/0.3.02) - https://cosm.com
Host: requestb.in
Content-Type: application/x-www-form-urlencoded
Content-Length: 918
Connection: close

body=%7B%22id%22%3A7443%2C%22url%22%3A%22http%3A%2F%2Fapi.cosm.com%2Fv2%2Ftriggers%2F7443%22%2C%22type%22%3A%22lt%22%2C%22threshold_value%22%3A%2220%22%2C%22timestamp%22%3A%222013-04-14T09%3A50%3A47.590044Z%22%2C%22environment%22%3A%7B%22id%22%3A57346%2C%22feed%22%3A%22http%3A%2F%2Fapi.cosm.com%2Fv2%2Ffeeds%2F57346%22%2C%22title%22%3A%22Macbook+Battery+Level%22%2C%22description%22%3A%22%22%2C%22private%22%3Afalse%2C%22location%22%3A%7B%22lat%22%3Anull%2C%22lon%22%3Anull%2C%22name%22%3A%22%22%7D%7D%2C%22triggering_datastream%22%3A%7B%22id%22%3A%22battery%22%2C%22url%22%3A%22http%3A%2F%2Fapi.cosm.com%2Fv2%2Ffeeds%2F57346%2Fdatastreams%2Fbattery%22%2C%22at%22%3A%222013-04-14T09%3A50%3A02.406927Z%22%2C%22value%22%3A%7B%22max_value%22%3A1724.0%2C%22min_value%22%3A0.0%2C%22value%22%3A%2226.28%22%7D%2C%22units%22%3A%7B%22type%22%3Anull%2C%22symbol%22%3A%22%25%22%2C%22label%22%3Anull%7D%7D%2C%22debug%22%3Atrue%7D

不幸的是,我不是 C# 专家,但我怀疑问题与未配置为从标准 urlencoded 请求正文中提取 JSON 正文的服务有关,但也许这可能为如何弄清楚发生了什么提供了线索对于知道 C# 的人来说是错误的。

于 2013-04-14T10:04:09.683 回答
0

经过测试和工作的代码 -

[OperationContract]  
[WebInvoke(Method = "POST",  
BodyStyle = WebMessageBodyStyle.WrappedRequest,  
UriTemplate = "cosm")]  
string cosmStream(Stream body);
于 2013-04-14T22:21:13.413 回答