I am currently working with a generic handler in asp.net. I believe it is currently in a sort of “listening” state awaiting POSTs. I am expecting a POST with a filename Header, and once received the handler will deal with downloading the file. My handler code is below:
Sub ProcessRequest(Byval context as HttpContext) Implements IHttpHanlder.ProcessRequest
If context.Request.HttpMethod() = "POST" Then
Dim Reader as New StreamReader(context.Request.InputStream)
Dim contents as String = reader.ReadtoEnd()
Dim filename as String = context.Request.Headers(("filename"))
System.IO.File.Writealltext(ConfigurationManager.AppSettings("outputdirectory"), contents)
Else
context.Response.ContentType = "text/plain"
context.Response.ContentType("Handler is alive")
End If
End Sub
I would like to replicate a post and see if it takes it in successfully. Would it be possible to generate and send this post from another program on my machine. I have attempted a few tutorials including this one
I feel that I have gotten the closest using this code(from previous link)
Using wc as New System.Net.WebClient
wc.UploadFile("http://localhost:Port/local/of/handler", "C:\local\of\file.txt")
End Using
I am receiving a 500 error from the remote server. Would this be an issue with the handlers code? Or am I just not making the right type of POST?
When messing around with wc.Headers()/Darin’s suggestion I still get a 500 error. The exception is below.
System.Net.WebException: The remote server returned an error: (500) Internal Server Error
at System.Net.HttpWebRequest.GetResponse()
at System.Net.Webclient.GetWebResponse(WebRequest request)
at System.Net.WebClient.WebClientWriteStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Stream.Dispose()
at TestPOSTGETEXE.Form1.Button4_Click(Object sender, EventArgs e) in C:\blah\blah\..\..\..\
Try like this: