-
March 28th, 2015, 07:42 AM
#1
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.
-
March 28th, 2015, 07:49 AM
#2
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)
-
March 28th, 2015, 07:56 AM
#3
Re: Upload Data using c++.
So, what can I do for removing these errors.
-
March 28th, 2015, 12:06 PM
#4
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)
-
April 16th, 2015, 01:41 PM
#5
Re: Upload Data using c++.
i need sequential pattern mining (ISE) C/ C++ Source code. plz help.
-
April 16th, 2015, 02:34 PM
#6
Re: Upload Data using c++.
Originally Posted by malsoru@gmail.com
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|