【发布时间】:2014-12-28 01:31:11
【问题描述】:
在我的 Visual Studio 13 控制台应用程序中,我在 TCP-Socket 上接收到以下字节流(从嵌入式设备接收):
POST /setup HTTP/1.1
Content-Length: 6
Content-Type: application/setup+tlv8
TLV8-data
虽然它似乎是一个有效的 http 请求,但我的以下尝试都没有成功将其识别为 http 请求:(在常规 HTTP 请求上它们可以正常工作)
- .NET HttpListener 类(甚至不通知我任何请求已被调用)
- Grapevine(同样的,在 POST 或 GET 上给出任何路由)https://github.com/scottoffen/Grapevine
- Alchemy(OnConnect 方法已被调用,但在相应的 UserContext 中我只是看到请求路径:/。与此报告的问题类似:https://github.com/Olivine-Labs/Alchemy-Websockets/issues/70
到目前为止,我实际上只对 POST 或 GET 请求的 path 以及正文中附加的 content(tlv 格式)感兴趣。
我配置错了吗?例如:我需要告诉正确的内容类型? 有什么办法可以摆脱编写自己的简单文本解析器?
grapevine的代码示例:
private void init()
{
s = new PairServer();
s.Host = "172.28.22.78";
s.Port = "52025";
s.Start();
}
提供以下服务器类:
public class PairServer : RestServer
{
[RestRoute(Method = HttpMethod.POST, PathInfo = @"^/setup")]
[RestRoute(Method = HttpMethod.GET, PathInfo = @"^/setup")]
public void PairSetup(HttpListenerContext context)
{
// will not reach here
}
[RestRoute(Method = HttpMethod.POST)]
public void AnyRoute(HttpListenerContext context)
{
// Not even here
}
【问题讨论】:
-
您的代码似乎有问题。但是,除非我们有code or information that can reproduce the problem,否则我们无能为力。否则,我们只是在盲目猜测。
标签: c# http-post httprequest httplistener grapevine