代码之家  ›  专栏  ›  技术社区  ›  Patrick

400.0-MSXML2::IXMLHTTPRequestPtr的错误请求

  •  1
  • Patrick  · 技术社区  · 15 年前

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

    在浏览器中粘贴时,xml将按预期显示。在我的软件中,我正在使用:

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

    并得到以下回应:

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

    进行调用的函数是:

    #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;
    }
    

    当ForceNocache设置为false时,该函数可以正常工作,使If-Modified标头出现问题。。。如果我不明白为什么不喜欢这个(iis 7),我会提出一个新问题,但是如果这里有人能给我指出正确的方向,这将节省一些噪音。

    谢谢你的帮助。

    2 回复  |  直到 15 年前
        1
  •  1
  •   erlando    15 年前

    根据这篇Microsoft知识库文章,您可能遇到某种数据包损坏:

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

    只是出于兴趣,你在使用时也有同样的体验吗 IServerXMLHTTPRequestPtr

        2
  •  1
  •   Community CDub    8 年前

    我想我找到了你的答案,你必须在日期前加上0。

    XmlHttpRequest with If-Modified since, webserver returns "400 Bad Request"

    推荐文章