我目前正在使用asp.net中的通用處理程序。我相信它目前處於等待POST的「聆聽」狀態。我期待一個帶有文件名Header的POST,一旦收到處理程序將處理下載文件。我的處理程序代碼如下:HTTP POST要自測試處理程序
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錯誤服務器。這是處理程序代碼的問題嗎?或者我只是沒有做出正確的POST類型?
當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\..\..\..\
你的客戶端代碼甚至沒有嘗試設置你的處理程序代碼預計頭。 –
我將編輯我已經搞砸了諸如wc.Headers.Add之類的東西,但似乎並沒有得到它直 – sealz
「搞亂」不如實際的代碼有幫助。 –