在 ASP.NET 中使用 REST YAML Web 服务
我正在使用 PandaStream,它将 REST 通知作为 YAML 发送到我们的 ASP.NET 应用程序。我的 Web 服务阻塞并返回 500,因为它尝试将内容解析为 XML。我怎样才能停止这个解析?如何将内容作为一个大字符串来获取,以便我可以自己解析它?
[WebMethod]
//HOWTO? suppress XML parsing
public void UpdateStatus()
{
// HOWTO? get content as string
// parse string as YAML
// ...
}
更新:好的,如果我使用常规 .aspx 页面,如何获取字符串形式的原始 POST 内容?
更新 2:我可以得到文本:
Stream s = Request.InputStream;
byte[] buffer = new byte[s.Length];
s.Read(buffer, 0, (int)s.Length);
String content = bytesToString(buffer);
...但它搞砸了。 yaml 的开头行是:
---
:video:
:thumbnail: bac01bf0-503a-012b-1406-123138002145.flv_thumb.jpg
:duration: 15900
...等等,但在我的字符串中,这变成:
video=---%20%0a%3avideo%3a%20%0a%20%20%3athumbnail%3a%20bac01bf0-503a-012b-1406-123138002145.flv_thumb.jpg%0a%20%20%3aduration%3a%2015900
当我只想要原始内容时,ASP 似乎正在“参数化”POST 主体。这与哑剧类型有关吗?
I'm using PandaStream, which sends a REST notification as YAML to our ASP.NET app. The web service I have chokes and returns 500 because it attempts to parse the content as XML. How can I stop this parsing? How do I get the content as just a big string so I can parse it myself?
[WebMethod]
//HOWTO? suppress XML parsing
public void UpdateStatus()
{
// HOWTO? get content as string
// parse string as YAML
// ...
}
UPDATE: OK, if I use a regular .aspx page, how do I get the raw POST content as a string?
UPDATE 2: I can get the text:
Stream s = Request.InputStream;
byte[] buffer = new byte[s.Length];
s.Read(buffer, 0, (int)s.Length);
String content = bytesToString(buffer);
...but it gets screwed up. The opening lines of the yaml are:
---
:video:
:thumbnail: bac01bf0-503a-012b-1406-123138002145.flv_thumb.jpg
:duration: 15900
...and so on, but in my string this becomes:
video=---%20%0a%3avideo%3a%20%0a%20%20%3athumbnail%3a%20bac01bf0-503a-012b-1406-123138002145.flv_thumb.jpg%0a%20%20%3aduration%3a%2015900
It seems ASP is "parameterizing" the POST body when I just want the raw stuff. Is this something to do with the mime type?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ASMX Web 服务只能处理输入上的 SOAP。如果您需要读取其他格式,那么您不需要使用 ASMX Web 服务。
只需使用普通页面或 HttpHandler,然后进行自己的解析即可。
ASMX Web Services can only process SOAP on input. If you need to read some other format, then you need to not be using an ASMX web service.
Just use a normal page, or an HttpHandler, and do your own parsing.