HttpSendRequest faulty on Vista when authentication needed ? - Programmer

This is a discussion on HttpSendRequest faulty on Vista when authentication needed ? - Programmer ; Hi Have anyone bumped into problems using InternetOpen(), InternetConnect() with or without credentials and HttpOpenRequest etc? The thing is that the API's do NOT return errors and it works perfectly on XP and Windows 2000. But what happens is that, ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: HttpSendRequest faulty on Vista when authentication needed ?

  1. HttpSendRequest faulty on Vista when authentication needed ?

    Hi

    Have anyone bumped into problems using InternetOpen(), InternetConnect()
    with or without credentials and HttpOpenRequest etc?
    The thing is that the API's do NOT return errors and it works perfectly on
    XP and Windows 2000.

    But what happens is that, only on Vista (Enterprise edition), it causes
    something to return

    BAD REQUEST


    instead of the text when an account and password is specified. I can't see
    anything about it in IIS logs so i guess IIS just ignores it.
    I think it looks like automatically created header information gets corrupt.

    If credentials are left out in InternetConnect, to use automatic domain
    authentication, it returns html that says the user isn't authenticated and
    the IIS logs doesn't see an account either. I also tried setting username
    and password using InternetSetOption().

    I have been browsing lots of googled docs out there including online
    references for the API's but haven't found anything fully related.
    Ok, here is the code. Any ideas? Is some special manifest needed? Maybe
    IE7's protected mode is causing it? Help!

    char *Http_p_szRead(DWORD dwTimeout)
    {
    char *p_szBuff, *p_szB, sz[1001];
    HINTERNET hInet, hInetS, hInetURL;
    DWORD dw;
    int n;
    char *p_szX= "CONTENT-TYPE: application/x-www-form-urlencoded;
    charset=ISO-8859-1\r\n";
    char *p_szPW="iPWVistaGenPilot";
    unsigned long ul;
    if ((hInet=InternetOpen("SetAdmPwWTSV", INTERNET_OPEN_TYPE_DIRECT , NULL,
    NULL, 0))==NULL) return NULL;
    ul=dwTimeout; if (ul<5000) ul=5000;
    InternetSetOption(hInet, INTERNET_OPTION_CONNECT_TIMEOUT, &ul, sizeof(ul));
    hInetS=InternetConnect(hInet, "server.company.net",
    INTERNET_DEFAULT_HTTP_PORT,
    NULL, NULL, // or "account", "password" for IIS server
    INTERNET_SERVICE_HTTP, 0, 0);
    if (hInetS==NULL) { dw=GetLastError(); InternetCloseHandle(hInet); return
    NULL; } // failure
    sprintf(sz, "/");
    hInetURL=HttpOpenRequest(hInetS, "GET", sz, "HTTP/1.1", NULL, "text/*",
    INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_NO_CAC HE_WRITE|INTERNET_FLAG_PRAGMA_NOCACHE,
    0);
    if (hInetURL==NULL) { dw=GetLastError(); InternetCloseHandle(hInet);
    InternetCloseHandle(hInetS); return NULL; } // failure
    if (!HttpSendRequest(hInetURL, NULL, -1, NULL, 0))
    { dw=GetLastError(); InternetCloseHandle(hInet); return NULL; } // failure
    p_szBuff=malloc(10001); p_szB=p_szBuff; dw=0; n=0;
    *p_szB=0;
    if (!InternetQueryDataAvailable(hInetURL, &dw, 0, 0))
    { InternetCloseHandle(hInetS); InternetCloseHandle(hInet); return NULL; }
    while (InternetReadFile(hInetURL, p_szB, 9990, &dw))
    {
    if (dw==0)
    { n++; if (n>5) break; if (p_szB==p_szBuff) Sleep(1000); else Sleep(200); }
    p_szB+=dw; dw=p_szB-p_szBuff; p_szBuff=realloc(p_szBuff, dw+10001);
    p_szB=p_szBuff+dw;
    }
    // reallocate the memory buffer and end the http request
    dw=p_szB-p_szBuff;
    if (dw==0) { free(p_szBuff); p_szBuff=NULL; }
    else { p_szBuff=realloc(p_szBuff, dw + 101); p_szBuff[dw]='\0';
    p_szBuff[dw+1]='\0'; }
    HttpEndRequest(hInetURL, NULL, HSR_SYNC, 0);
    InternetCloseHandle(hInetS); InternetCloseHandle(hInet);
    return p_szBuff;
    }



  2. Re: HttpSendRequest faulty on Vista when authentication needed ?


    "Sten Westerback (MVP SDK 2005-6 "
    wrote in message
    news:1192108671.700021@xnews001...
    > Hi
    >
    > Have anyone bumped into problems using InternetOpen(), InternetConnect()
    > with or without credentials and HttpOpenRequest etc?
    > The thing is that the API's do NOT return errors and it works perfectly on
    > XP and Windows 2000.
    >
    > But what happens is that, only on Vista (Enterprise edition), it causes
    > something to return
    >

    BAD REQUEST


    > instead of the text when an account and password is specified. I can't see
    > anything about it in IIS logs so i guess IIS just ignores it.
    > I think it looks like automatically created header information gets
    > corrupt.
    >
    > If credentials are left out in InternetConnect, to use automatic domain
    > authentication, it returns html that says the user isn't authenticated and
    > the IIS logs doesn't see an account either. I also tried setting username
    > and password using InternetSetOption().
    >
    > I have been browsing lots of googled docs out there including online
    > references for the API's but haven't found anything fully related.
    > Ok, here is the code. Any ideas? Is some special manifest needed? Maybe
    > IE7's protected mode is causing it? Help!
    >
    > char *Http_p_szRead(DWORD dwTimeout)
    > {
    > char *p_szBuff, *p_szB, sz[1001];
    > HINTERNET hInet, hInetS, hInetURL;
    > DWORD dw;
    > int n;
    > char *p_szX= "CONTENT-TYPE: application/x-www-form-urlencoded;
    > charset=ISO-8859-1\r\n";
    > char *p_szPW="iPWVistaGenPilot";
    > unsigned long ul;
    > if ((hInet=InternetOpen("SetAdmPwWTSV", INTERNET_OPEN_TYPE_DIRECT , NULL,
    > NULL, 0))==NULL) return NULL;
    > ul=dwTimeout; if (ul<5000) ul=5000;
    > InternetSetOption(hInet, INTERNET_OPTION_CONNECT_TIMEOUT, &ul,
    > sizeof(ul));
    > hInetS=InternetConnect(hInet, "server.company.net",
    > INTERNET_DEFAULT_HTTP_PORT,
    > NULL, NULL, // or "account", "password" for IIS server
    > INTERNET_SERVICE_HTTP, 0, 0);
    > if (hInetS==NULL) { dw=GetLastError(); InternetCloseHandle(hInet); return
    > NULL; } // failure
    > sprintf(sz, "/");
    > hInetURL=HttpOpenRequest(hInetS, "GET", sz, "HTTP/1.1", NULL, "text/*",
    > INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_NO_CAC HE_WRITE|INTERNET_FLAG_PRAGMA_NOCACHE,
    > 0);
    > if (hInetURL==NULL) { dw=GetLastError(); InternetCloseHandle(hInet);
    > InternetCloseHandle(hInetS); return NULL; } // failure
    > if (!HttpSendRequest(hInetURL, NULL, -1, NULL, 0))
    > { dw=GetLastError(); InternetCloseHandle(hInet); return NULL; } // failure
    > p_szBuff=malloc(10001); p_szB=p_szBuff; dw=0; n=0;
    > *p_szB=0;
    > if (!InternetQueryDataAvailable(hInetURL, &dw, 0, 0))
    > { InternetCloseHandle(hInetS); InternetCloseHandle(hInet); return
    > NULL; }
    > while (InternetReadFile(hInetURL, p_szB, 9990, &dw))
    > {
    > if (dw==0)
    > { n++; if (n>5) break; if (p_szB==p_szBuff) Sleep(1000); else
    > Sleep(200); }
    > p_szB+=dw; dw=p_szB-p_szBuff; p_szBuff=realloc(p_szBuff, dw+10001);
    > p_szB=p_szBuff+dw;
    > }
    > // reallocate the memory buffer and end the http request
    > dw=p_szB-p_szBuff;
    > if (dw==0) { free(p_szBuff); p_szBuff=NULL; }
    > else { p_szBuff=realloc(p_szBuff, dw + 101); p_szBuff[dw]='\0';
    > p_szBuff[dw+1]='\0'; }
    > HttpEndRequest(hInetURL, NULL, HSR_SYNC, 0);
    > InternetCloseHandle(hInetS); InternetCloseHandle(hInet);
    > return p_szBuff;
    > }


    I found the cause now -- i had missinterpreted the type of the
    lpszAcceptType parameter of HttpOpenRequest().
    I suppose the Vista version of the Inet functions do better checks but i
    think HttpOpenRequest should fail in that case.
    In any case i think it should be renamed lplpszAcceptTypeArray or similar in
    the documentation.

    - Sten



+ Reply to Thread