httplistenerrequest

HttpListener how to serve images

倾然丶 夕夏残阳落幕 提交于 2020-01-30 06:55:07
问题 I'm making a simple webserver to serve html, css, js & images (done in c#). I am using HttpListener and I can get the html, javascript and css files to work properly. I am just having trouble with the images. This is what I'm using currently: if (request.RawUrl.ToLower().Contains(".png") || request.RawUrl.Contains(".ico") || request.RawUrl.ToLower().Contains(".jpg") || request.RawUrl.ToLower().Contains(".jpeg")) { string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly

Httplistener and file upload

半腔热情 提交于 2019-12-17 16:08:09
问题 I am trying to retrieve an uploaded file from my webserver. As the client sends its files through a webform (random files), I need to parse the request to get the file out and to process it further on. Basically, the code goes as: HttpListenerContext context = listener.GetContext(); HttpListenerRequest request = context.Request; StreamReader r = new StreamReader(request.InputStream, System.Text.Encoding.Default); // this is the retrieved file from streamreader string file = null; while ((line

C# HttpListener: storing posted file is always 2 byte larger than original

China☆狼群 提交于 2019-12-11 13:21:16
问题 Problem description: I have an HttpListener within my C# program that takes a POST request with a posted file (jpg, doc, zip or alike). I am sending and receiving the file on the same Windows machine. I took the code from https://stackoverflow.com/a/8468520/241475 (coming from the Java world, I'm fairly new to C#/.Net), which is said to just be a proof of concept, and the upload and storing of data on the server side almost works fine, except that the stored files is always 2 bytes larger

HttpListener in Azure cloud service

拈花ヽ惹草 提交于 2019-12-11 07:05:55
问题 I am trying to develop a service to be deployed as an Azure Cloud Service. This service needs to listen for HttpRequests, and process them as they're received. Thus far, I have created a simple Azure Cloud Service project in VS2017 with a single worker-role, which handles requests sent to /Localhost:8080/ like so: public class WorkerRole : RoleEntryPoint { public override void Run() { this.runasync(this.cancellationTokenSource.Token).Wait(); } finally { this.runCompleteEvent.Set(); } public

Getting form data from HttpListenerRequest

左心房为你撑大大i 提交于 2019-12-09 14:47:09
问题 I have a HttpListenerRequest which was initiated from a html <form> that was posted. I need to know how to get the posted form values + the uploaded files. Does anyone know of an example to save me the time doing it for myself? I've had a google around but not found anything of use. 回答1: The main thing to understand is that HttpListener is a low level tool to work with http requests. All post data is in HttpListenerRequest.InputStream stream. Suppose we have a form like that: <form method=\

Getting form data from HttpListenerRequest

a 夏天 提交于 2019-12-04 01:26:08
I have a HttpListenerRequest which was initiated from a html <form> that was posted. I need to know how to get the posted form values + the uploaded files. Does anyone know of an example to save me the time doing it for myself? I've had a google around but not found anything of use. The main thing to understand is that HttpListener is a low level tool to work with http requests. All post data is in HttpListenerRequest.InputStream stream. Suppose we have a form like that: <form method=\"post\" enctype=\"multipart/form-data\"><input id=\"fileUp\" name=\"fileUpload\" type=\"file\" /><input type=\

HttpListener - how do I send a WebException HTTP 304 “Not Modified” error back to browser?

扶醉桌前 提交于 2019-12-01 22:52:55
问题 How do I mimic a WebException 304 error back to browser if I am using HttpListener? That is I have received a request to my HttpListener, and then obtained the HttpListenerContext, then from this point how would I mimic/arrange for a HTTP "304 Not Modified" response to be effectively sent back to the browser via the HttpListenerContext.response? EDIT: I tried the following however I get an error trying to copy WebException.Status to HttpWebResponse.StatusCode (The status code must be exactly

Httplistener and file upload

这一生的挚爱 提交于 2019-11-27 22:20:32
I am trying to retrieve an uploaded file from my webserver. As the client sends its files through a webform (random files), I need to parse the request to get the file out and to process it further on. Basically, the code goes as: HttpListenerContext context = listener.GetContext(); HttpListenerRequest request = context.Request; StreamReader r = new StreamReader(request.InputStream, System.Text.Encoding.Default); // this is the retrieved file from streamreader string file = null; while ((line = r.ReadLine()) != null){ // i read the stream till i retrieve the filename // get the file data out