gpt4 book ai didi

c# - C# 中是否有任何多部分/表单数据解析器 - (无 ASP)

转载 作者:太空狗 更新时间:2023-10-29 18:01:18 24 4
gpt4 key购买 nike

我只是想写一个多部分解析器,但事情变得复杂了,想问问是否有人知道用 C# 编写的现成解析器!

澄清一下,我正在编写自己的“微型”http 服务器,并且还需要解析多部分表单数据!

提前致谢,咕噜咕噜

最佳答案

我开源了一个 C# Http 表单解析器 here .

这比 CodePlex 上提到的另一个稍微灵活一些,因为您可以将它用于多部分和非多部分 form-data,并且它还为您提供其他格式化的表单参数在 Dictionary 对象中。

这可以按如下方式使用:

非多部分

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# - C# 中是否有任何多部分/表单数据解析器 - (无 ASP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3880530/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com