我目前正在使用asp.net中的一个通用处理程序。我相信它目前正处于一种等待发帖的“监听”状态。我期待一个带有文件名标题的帖子,一旦收到,处理程序将处理下载文件。我的处理程序代码如下:
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我想复制一个帖子,看看它是否成功地接受了它。是否有可能从我机器上的另一个程序生成并发送此帖子。我已经尝试了几个教程,包括这个
我觉得我已经得到了最近的使用这个代码(从前面的链接)
Using wc as New System.Net.WebClient
wc.UploadFile("http://localhost:Port/local/of/handler", "C:\local\of\file.txt")
End Using我收到来自远程服务器的500错误。这会是处理程序代码的问题吗?或者我只是没有做出正确的帖子类型?
在处理wc.Headers()/Darin的建议时,我仍然得到一个500错误。例外情况如下。
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\..\..\..\发布于 2012-01-19 22:05:40
试着这样做:
Using wc As New System.Net.WebClient
wc.Headers("filename") = "file.txt"
Using writer = wc.OpenWrite("http://localhost:Port/local/of/handler")
Dim file = System.IO.File.ReadAllBytes("C:\local\of\file.txt")
writer.Write(file, 0, file.Length)
End Using
End Usinghttps://stackoverflow.com/questions/8927326
复制相似问题