tags:

views:

303

answers:

2

I'm trying to access an xml file over http. The address is similar to:

http://localhost/app/config/file.xml

When pasting this in a browser the xml is displayed as expected. In my software I am using:

MSXML2::IXMLHTTPRequestPtr rp;
...
rp->open( "GET" , "http://localhost/app/config/file.xml" );

and getting the following response:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"     
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; 
<html xmlns="http://www.w3.org/1999/xhtml"&gt; 
<head> 
<title>IIS 7.0 Detailed Error - 400.0 - Bad Request</title> 
<style type="text/css"> 
<!

Does anyone have any ideas what might be happening?

EDIT: more info, when trying to connect to another server in the office (which I can connect to fine using a browser) I'm getting a response of "Bad Request" and no more.

The function making the call is:

#import "msxml3.dll"

BOOL HTTPGet(LPCTSTR URL, CString &Response, long Timeout, BOOL ForceNoCache )
{
BOOL ret = FALSE;

MSXML2::IXMLHTTPRequestPtr rp;
//MSXML2::IServerXMLHTTPRequestPtr rp;

try
{
    HRESULT hr = rp.CreateInstance( __uuidof( MSXML2::XMLHTTP ) );
    //HRESULT hr = rp.CreateInstance( __uuidof( MSXML2::ServerXMLHTTP30 ) );

    if( SUCCEEDED( hr ) )
    {
        rp->open( "GET" , URL );
        if( ForceNoCache )
            rp->setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 1970 00:00:00 GMT" );
        rp->send();

        for( DWORD tc = GetTickCount() ; rp->readyState != 4 && GetTickCount() < tc + Timeout ; )
        {
            Sleep( 50 );
            //WaitMessage();
            for( MSG msg ; PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) ; )
            {
                TranslateMessage( &msg );
                DispatchMessage( &msg );
            }

        }

        if( rp->readyState == 4 )
        {
            Response = (LPCSTR)rp->responseText;
            ret = TRUE;
        }
        else
            Response = "Timed out";
    }
}
catch( CException &e )
{
    char err[ 2048 ];
    if( e.GetErrorMessage( err , sizeof( err ) ) )
        Response = err;
    else
        Response = "Unhandled exception";
}
catch( _com_error &e )
{
    Response = e.ErrorMessage();
}
catch( ... )
{
    Response = "Unhandled exception";
}

return ret;
}

EDIT2: The function works correctly when ForceNocache set to false making the If-Modified-Since header the problem... I'll start up a new question if I can't work out why this isn't liked (by iis 7) but if someone here can point me in the right direction it will save some noise.

Thanks for all your help.

+1  A: 

According to this Microsoft knowledge base article you may be experiencing some kind of packet corruption:

Error Message: HTTP/1.1 Error 400 - Bad Request (KB247249)

Just out of interest, do you experience the same when using IServerXMLHTTPRequestPtr?

Kev
Unlikely to happen repeatedly when I can connect to the same site from the same computer using a different MS product.
Patrick
Yes same response with IServerXMLHTTPRequestPtr
Patrick
+1  A: 

I think I found your answer, you have to prefix the date with 0.

http://stackoverflow.com/questions/2517242/xmlhttprequest-with-if-modified-since-webserver-returns-400-bad-request/

Kind regards,

Matthias Vance

Matthias Vance