首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >HTTP Post To Self To Test Handler

HTTP Post To Self To Test Handler
EN

Stack Overflow用户
提问于 2012-01-19 22:01:12
回答 1查看 595关注 0票数 0

我目前正在使用asp.net中的一个通用处理程序。我相信它目前正处于一种等待发帖的“监听”状态。我期待一个带有文件名标题的帖子,一旦收到,处理程序将处理下载文件。我的处理程序代码如下:

代码语言:javascript
运行
复制
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

我想复制一个帖子,看看它是否成功地接受了它。是否有可能从我机器上的另一个程序生成并发送此帖子。我已经尝试了几个教程,包括这个

SO - POST Tutorial

我觉得我已经得到了最近的使用这个代码(从前面的链接)

代码语言:javascript
运行
复制
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错误。例外情况如下。

代码语言:javascript
运行
复制
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\..\..\..\
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-19 22:05:40

试着这样做:

代码语言:javascript
运行
复制
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 Using
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8927326

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档