CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2002
    Location
    Pakistan
    Posts
    5

    Question Web Application InternetWriteFile API

    Hello. I am using InternetWriteFile API to upload a file in site of my own IIS(i.e. on my own PC). The name of the file to upload is uploaded.txt which is 25 bytes in size. But when I see the directory of my website then it show name of the file & it's size is zero bytes. Why aren't the contents of the source file written. I've all the rights.

    So whats the problem?

    I am sending attached file for win32 project. IF IT DOESN'T HAPPEN BCUZ OF FIREWALL, THEN I am sending source code of the function which uses this API.

    ////// function body starts //////////
    void MyhttpSendRequestWrite(HWND hwnd){
    HINTERNET hInternetSession, hURL, hConnect, hHttpRequest;
    char buff[3000] = "This is the uploaded file";
    DWORD bytesWritten = 10, dwContext, err;

    hInternetSession = InternetOpen("Microsoft Internet Explorer",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    hConnect = InternetConnect(hInternetSession,"localhost", INTERNET_DEFAULT_HTTP_PORT,"idrees", NULL, INTERNET_SERVICE_HTTP, 0, 0);
    hHttpRequest = HttpOpenRequest(hConnect, "PUT", "MyWebDirectory/uploaded.txt", "1.1", "localhost", NULL, INTERNET_FLAG_HYPERLINK, dwContext); ///UltWeb/UltISAPI/ultISAPI.dll?default

    if(!HttpSendRequest(hHttpRequest, NULL, NULL, NULL, 100)){
    MessageBox(NULL,"HttpSendRequest Failed","http Failiur",MB_OK);
    return;
    }
    short count=0;char tf;
    DWORD total=0;

    //Error is in the following statement
    tf = InternetWriteFile(hHttpRequest, buff, sizeof(buff), &bytesWritten);//Not writing contents of file

    InternetCloseHandle(hInternetSession);
    }
    ////// function body ends //////////
    Attached Files Attached Files

  2. #2
    Join Date
    Aug 2002
    Posts
    33
    You missed the 3rd argument, which is buff. It suppose to be like this

    if (!HttpSendRequest(hHttpRequest, NULL, NULL, buff, 100)){
    MessageBox(NULL,"HttpSendRequest Failed","http Failiur",MB_OK)

  3. #3
    Join Date
    Sep 2002
    Location
    Pakistan
    Posts
    5
    I want information on InternetWriteFile not HttpSendRequest. InternetWriteFile is not working & giving this error ERROR_INTERNET_INCORRECT_HANDLE_STATE.

    If u can modify my code or u can give me a small code whose InternetWriteFile API works correctly then plz post.

  4. #4
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    13

    InternetWriteFile

    I think you need to use HttpSendrequestEx() and InternetWriteFile() together. instead of using HttpSendRequest()

    check the following artical for reference:
    http://support.microsoft.com/default...;en-us;Q184352

    Yiping

  5. #5
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    13

    httpsendrequest

    By the way, StevenHoang was right to use HttpSenRequest(..). In this case, you do not need InternetWriteFile.
    Yiping

  6. #6
    Join Date
    Sep 2000
    Posts
    11

    why InternetWriteFile fail

    Sorry ,My english is pool.....
    I use above code to write file to http server,but receive 401.3 error,ACL not allow me to write.
    So I use Administrator to write ,but the error still occurs,why?Someone can help me?

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