简体   繁体   English

C#Web服务器从浏览器接收文件

[英]c# web server to receive a file from browser

Iam writing a light weight web server in c# using TcpListener class. 我使用TcpListener类在c#中编写轻量级的Web服务器。 I need to get an image file(jpeg, png) from the browser and store it in the web server directory. 我需要从浏览器获取图像文件(jpeg,png)并将其存储在Web服务器目录中。 I searched over the internet but i couldn't able to get an answer. 我通过互联网搜索,但无法获得答案。 I can able to send image as response to the client(browser) using socket.send(byteArray, byteArray.Length, 0) but i don't know how to receive an image from the client. 我可以使用socket.send(byteArray,byteArray.Length,0)发送图像作为对客户端(浏览器)的响应,但是我不知道如何从客户端接收图像。

Google is your friend. Google是您的朋友。

Here's a simple example, just modify to suit your needs. 这是一个简单的示例,只需进行修改即可满足您的需求。

http://www.switchonthecode.com/tutorials/csharp-tutorial-simple-threaded-tcp-server http://www.switchonthecode.com/tutorials/csharp-tutorial-simple-threaded-tcp-server

EDIT: Adding code for writing byte array to file: 编辑:添加用于将字节数组写入文件的代码:

File.WriteAllBytes(@"MyFile.txt", byteArray);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM