Microsoft KB Archive/308607

= PRB: ServerXMLHTTP Cannot Intercept a Redirected Request =

Article ID: 308607

Article Last Modified on 4/30/2002

-

APPLIES TO


 * Microsoft XML Core Services 4.0
 * Microsoft XML Parser 3.0 Service Pack 1
 * Microsoft XML Parser 3.0 Service Pack 2
 * Microsoft XML Core Services 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:

http://msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/msdn-files/027/001/655/msdncompositedoc.xml

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(&quot;Msxml2.ServerXMLHTTP.4.0&quot;) sxh.open &quot;POST&quot;, &quot;http://webserver1/SXH/redirect1.asp&quot;, false sxh.send Response.Write &quot;This is from Sending.ASP &quot; Response.Write sxh.getResponseHeader(&quot;header1&quot;) %> Redirect1.asp redirects the request to the Redirect2.asp page, as follows: <%   Response.AddHeader &quot;header1&quot;, &quot;This is header1 from Redirect 1&quot; Response.Redirect &quot;http://webserver1/redirect2.asp&quot; %> Redirect2.asp is as follows: <%   Response.AddHeader &quot;header1&quot;, &quot;This is header1 from Redirect 2&quot; %> ServerXMLHTTP executes Redirect2.asp, and then returns the &quot;header1&quot; HTTP header as follows: &quot;This is header1 from Redirect 2&quot;

