有没有在C#中任何multipart / form-data的解析器 - (NO ASP) [英] Are there any multipart/form-data parser in C# - (NO ASP)
问题描述
我只是想写一个多部分解析器但事情越来越复杂,想问问是否有人在C#中准备分析器知道!
I am just trying to write a multipart parser but things getting complicated and want to ask if anyone knows of a ready parser in C#!
只是为了澄清,我写我自己的微型HTTP服务器并且需要标准杆多部分表单数据呢!
Just to make clear, I am writing my own "tiny" http server and need to pars multipart form-data too!
在此先感谢,
Gohlool
Thanks in advance, Gohlool
推荐答案
我开源C#的HTTP表单解析器<一个HREF =https://bitbucket.org/lorenzopolidori/http-form-parser/src相对=nofollow>这里。
I open-sourced a C# Http form parser here.
这是略高于提到另一种是在CodePlex上,因为你可以用它为多部分和非多表单数据
,而且它给你其他的形式参数更灵活。格式化在词典
对象
This is slightly more flexible than the other one mentioned which is on CodePlex, since you can use it for both Multipart and non-Multipart form-data
, and also it gives you other form parameters formatted in a Dictionary
object.
这可以按如下方式使用:
This can be used as follows:
非多
public void Login(Stream stream)
{
string username = null;
string password = null;
HttpContentParser parser = new HttpContentParser(stream);
if (parser.Success)
{
username = HttpUtility.UrlDecode(parser.Parameters["username"]);
password = HttpUtility.UrlDecode(parser.Parameters["password"]);
}
}
多部分
public void Upload(Stream stream)
{
HttpMultipartParser parser = new HttpMultipartParser(stream, "image");
if (parser.Success)
{
string user = HttpUtility.UrlDecode(parser.Parameters["user"]);
string title = HttpUtility.UrlDecode(parser.Parameters["title"]);
// Save the file somewhere
File.WriteAllBytes(FILE_PATH + title + FILE_EXT, parser.FileContents);
}
}
这篇关于有没有在C#中任何multipart / form-data的解析器 - (NO ASP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!