Is there any score / form data parser in C # - (NO ASP)

I'm just trying to write a multi-parameter parser, but things get complicated and you want to ask if anyone knows about a ready-made parser in C #!

Just to clarify, I am writing my β€œtiny” http server and you need to also share the multi-format form data.

Thanks in advance, Gohlool

+7
c # parsing multipartform-data
source share
5 answers

I open the C # form open parser here .

This is slightly more flexible than the one mentioned above, which applies to CodePlex, since you can use it for both Multipart and non-Multipart form-data , and also provides other form parameters formatted in the Dictionary object.

This can be used as follows:

non-frequent

 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"]); } } 

of many

 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); } } 
+23
source share

I had some problems with the parser, which are based on parsing strings, especially with large files. I found that it would run out of memory and would not process binary data.

To deal with these problems, I opened my own attempt for the C # multipart / form-data parser here

See my answer here for more details.

+6
source share

Check out the new multi-user device and its subclasses (e.g. MultipartFormDataStreamProvider). You can create your own implementation if none of the built-in implementations are suitable for your use.

+1
source share

I had a similar problem that I recently solved thanks to Anthony at http://antscode.blogspot.com/ for a multi-frame parser.

Loading a file from Flex to WCF REST Stream problems (how to decode multi-page recording in REST WS)

0
source share

Now with Core, you now have access to the IFormCollection using HttpContext.Request.Form.

Image saving example:

  Microsoft.AspNetCore.Http.IFormCollection form; form = ControllerContext.HttpContext.Request.Form; using (var fileStream = System.IO.File.Create(strFile)) { form.Files[0].OpenReadStream().Seek(0, System.IO.SeekOrigin.Begin); form.Files[0].OpenReadStream().CopyTo(fileStream); } 
0
source share

All Articles