CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2015
    Posts
    2

    Upload Data using c++.

    I am using this code for uploading a data in web but here is some error in this code.
    here is a code.
    Code:
    #include <windows.h>
    #include <wininet.h>
    #include <tchar.h>
    #include <iostream>
    #include <string>
    #include <sstream>
    
    #pragma comment(lib, "ws2_32.lib")
    
    int main(){
    
    TCHAR hdrs[] = _T("Content-Type: application/x-www-form-urlencoded");
    TCHAR frmdata[] = _T("name=John+Doe&userid=hithere&other=P%26Q");
    LPCTSTR accept[] = {_T("*/*"), NULL};
    
    HINTERNET hSession = InternetOpen(_T("MyAgent"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    HINTERNET hConnect = InternetConnect(hSession, _T("http://localhost"), INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
    HINTERNET hRequest = HttpOpenRequest(hConnect, _T("POST"), _T("/upload.php"), NULL, NULL, accept, 0, 1);
    HttpSendRequest(hRequest, hdrs, _tcslen(hdrs), frmdata, _tcslen(frmdata));
    
    
    return 0;
    
    }
    Here is a php code.

    PHP Code:
    <?php

    $name 
    $_POST['name'];
    $userid $_POST['userid'];
    $other $_POST['other'];

    $myfile fopen("newfile.txt""w") or die("Unable to open file!");
    $txt1 $name."\n";
    fwrite($myfile$txt1);
    $txt2 $userid."\n";
    fwrite($myfile$txt2);
    $txt3 $other."\n";
    fwrite($myfile$txt3);
    fclose($myfile);

    ?>
    Here is a [liker error]. I am using dev c++ for compiling that.

  2. #2
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Upload Data using c++.

    In your c++ code you are not checking the various API function calls for failure.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Mar 2015
    Posts
    2

    Re: Upload Data using c++.

    So, what can I do for removing these errors.

  4. #4
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Upload Data using c++.

    After every call to an API you check for failure. eg for InternetOpen() it returns NULL for failure (https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx). So you code something like
    Code:
    HINTERNET hSession = InternetOpen(_T("MyAgent"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    if (hSession == NULL) {
         cout << "InternetOpen failure. Error: " << GetLastError() << endl;
         return 1;
    }
    and similarly for other function calls.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Apr 2015
    Posts
    1

    Re: Upload Data using c++.

    i need sequential pattern mining (ISE) C/ C++ Source code. plz help.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Upload Data using c++.

    Quote Originally Posted by malsoru@gmail.com View Post
    i need sequential pattern mining (ISE) C/ C++ Source code. plz help.
    Please, start a new thread and describe your problem more clear.
    Victor Nijegorodov

Tags for this Thread

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