我正在尝试使用 asp.net 为客户端将使用 serverxmlhttp 从处理程序请求信息的环境实现 http 句柄 (.ashx)。这是到目前为止的代码......
客户端.ASPX
<%@ Page Language="VB" %>
<%
On Error Resume Next
Dim myserver_url As String = "http://mydomain.com/Server.ashx"
Dim myparameters As String = "one=1&two=2"
Dim xmlhttp As Object
xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
xmlhttp.open("POST", myserver_url, False)
xmlhttp.Send(myparameters)
If xmlhttp.Status = 200 Then
Dim myresults As String = ""
myresults = xmlhttp.responsetext
Response.Clear()
Response.Write("<html><body><h1>" & myresults & "</h1></body></html>")
End If
xmlhttp = Nothing
%>
服务器.ASHX
<%@ WebHandler Language="VB" Class="MyServerClass" %>
Imports System
Imports System.Web
Public Class MyServerClass : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "text/plain"
context.Response.Write("hi there")
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
...我的问题是客户端代码中的 myresults 字符串始终为空。问题:http-handle 应该如何填充调用它的 xmlhttp 对象的 responsetext 属性?
附录:我也将 server.ashx 实现为 aspx 文件,但 myresults 仍然是空白的。这是那个代码。
服务器.ASPX
<%@ Page Language="VB" %>
<%
Response.ContentType = "text/plain"
Response.Write("hi there")
%>
提前感谢您的帮助!和平,亨利·E·泰勒