CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Jul 2005
    Posts
    3

    Unhappy InternetWriteFile

    I am attempting to "POST" a file to a web page using InternetWriteFile and get the error 12019 ERROR_INTERNET_INCORRECT_HANDLE_STATE. I am trying to do this without a user interface and need it to be done programatically. Here is what my code looks like:

    Initialize = InternetOpen("srrreport", //Name of Application Calling (Agent)
    INTERNET_OPEN_TYPE_DIRECT, //Access Type
    NULL, //Proxy Name
    NULL, //Proxy Bypass
    0); //Flags

    hConnect = InternetConnect(Initialize, // InternetOpen handle
    "ugunwd017154", // Server name
    80, // HTTPS port
    "", // User name
    "", // User password
    INTERNET_SERVICE_HTTP, // Service
    0, // Flags
    0); // Context

    hReq = HttpOpenRequest(hConnect, //InternetConnect handle
    "POST", //Method
    sendFile, //Object name
    NULL, //Version
    NULL, //Referrer
    NULL, //Extra headers
    INTERNET_FLAG_KEEP_CONNECTION &&
    INTERNET_FLAG_NO_CACHE_WRITE, //Flags
    0); //Context

    HANDLE hFile = CreateFile(upFile, //File name
    GENERIC_READ, //Desired Access
    FILE_SHARE_READ, //Share Mode
    NULL, //Security Attribute
    OPEN_EXISTING, //Creation Disposition
    FILE_ATTRIBUTE_NORMAL, //Flags and Attributes
    NULL); //Template File

    if(hFile == INVALID_HANDLE_VALUE)
    {
    printf("\nFailed to open local file %s.", upFile);
    return FALSE;
    }

    BufferIn.dwBufferTotal = GetFileSize(hFile, NULL);
    printf("File size is %d\n", BufferIn.dwBufferTotal);

    if(HttpSendRequest(hReq, NULL, 0, NULL,0))
    {
    DWORD sum = 0;
    do
    {
    if(!(bRead = ReadFile(hFile, pBuffer, sizeof(pBuffer), &dwBytesRead, NULL)))
    {
    printf("\nReadFile failed on buffer %lu.", GetLastError());
    result = FALSE;
    break;
    }
    if(!(bRet=InternetWriteFile(hReq, pBuffer, dwBytesRead, &dwBytesWritten)))
    {
    printf("\nInternetWriteFile failed %lu", GetLastError());
    if (GetLastError() == 12019)
    {
    cout << "\nERROR_INTERNET_INCORRECT_HANDLE_STATE\n" << endl;
    }
    result = FALSE;
    break;
    }
    sum += dwBytesWritten;
    }
    while(dwBytesRead == sizeof(pBuffer));

    CloseHandle(hFile);
    printf("\nActual written bytes: %d\n", sum);
    }

    /*close file , terminate server connection and
    deinitialize the wininet library*/
    InternetCloseHandle(hReq);
    InternetCloseHandle(hConnect);
    InternetCloseHandle(Initialize);
    // return 0;


    I get connected to the server with out any problems, it errors out when I gets to InternetWriteFile. Also, I can not use any of the .NET framework, has to be done with standard c/c++.

    Thanks for any help

    Chris
    Last edited by lareauc; July 6th, 2005 at 08:27 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured