PRB: ServerXMLHTTP Cannot Intercept a Redirected Request (308607)



The information in this article applies to:

  • Microsoft XML 3.0
  • Microsoft XML 3.0 SP1
  • Microsoft XML 3.0 SP2
  • Microsoft XML 4.0

This article was previously published under Q308607

SYMPTOMS

The ServerXMLHTTP object was introduced in MSXML 3.0 as a powerful way to handle server-to-server communication. When you use ServerXMLHTTP to send a request to an Active Server Pages (ASP) page that redirects the request to another page, ServerXMLHTTP cannot intercept the redirect.

CAUSE

Currently, ServerXMLHTTP does not offer a way to intercept redirects.

RESOLUTION

To work around this problem, you can use the WinHttpRequest component directly. WinHttpRequest is part of WinHTTP 5.0, which is included in the MSXML 4.0 release of the parser. WinHttpRequest is the base of the ServerXMLHTTP object, so it is highly compatible with ServerXMLHTTP, and switching to it is fairly straightforward.

To download the Software Development Kit (SDK) for WinHTTP, see the following Microsoft Developer Network (MSDN) Web site: The Readme.doc file that the WinHTTP SDK includes contains an example of intercepting redirects.

STATUS

This behavior is by design.

MORE INFORMATION

The SXH_OPTION_URL (numeric value -1) option was added to the SetOption method in ServerXMLHTTP.4.0. This new option permits a client to retrieve the final URL after a redirect, thereby providing a method for the client to verify whether any redirects occurred.

In the following example, ServerXMLHTTP requests an ASP page that redirects the request. The sending page (Sending.asp) uses ServerXMLHttp to send the request to the Redirect1.asp page, as follows:
<%
	dim sxh
  	set sxh = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")
	sxh.open "POST", "http://webserver1/SXH/redirect1.asp", false
	sxh.send()
	Response.Write "This is from Sending.ASP <BR>"
	Response.Write sxh.getResponseHeader("header1")
%>
				
Redirect1.asp redirects the request to the Redirect2.asp page, as follows:
<%
	Response.AddHeader "header1", "This is header1 from Redirect 1"
    	Response.Redirect "http://webserver1/redirect2.asp"
%>
				
Redirect2.asp is as follows:
<%
	Response.AddHeader "header1", "This is header1 from Redirect 2"
%>
				
ServerXMLHTTP executes Redirect2.asp, and then returns the "header1" HTTP header as follows:
"This is header1 from Redirect 2"
				

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

299566 HOWTO: Identify HTTP Errors When You Use the ServerXMLHTTP Object

290761 Frequently Asked Questions about ServerXMLHTTP


Modification Type:MajorLast Reviewed:4/30/2002
Keywords:kbprb KB308607