|
-
March 5th, 2003, 01:38 AM
#1
Send HTTP request.
Basically what I am looking for is the ability to send an http request to a specific address and dispose of the returned data.
Here is the situation. We are having a major remote database problem, so in the mean time we have come up with this workaround:
1. The c app send an http request to:
www.something.com?x=something&y=something&z=something
2. The webapp takes the variables passed in the address (x,y,z) and does it's thing.
So all the c app has to do is send the page request and kill the connection.
I am not the c developer, but he is having problems doing this, so I thought I would ask the good ol' codeguru community.
Thanks in advance for any help you can provide.
-
March 5th, 2003, 03:16 PM
#2
Post the section of code the developer is having problems with.
Kuphryn
-
March 5th, 2003, 04:53 PM
#3
When in doubt check the RFC. There might be something on w3.org too.
-
March 6th, 2003, 01:17 PM
#4
I sent the developer over to w3.org and this is what he came up with for testing:
#include <windows.h>
#include <wininet.h>
#include <iostream>
using namespace std;
void main () {
HINTERNET hinternet, hHTTPSession, hHTTPRequest;
hinternet = InternetOpen("Request", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (hinternet == NULL) {
cout << "InternetOpen() Failed - " << GetLastError() << endl;
return;
} else {
cout << "Internet session openend." << endl;
}
hHTTPSession = InternetConnect(hinternet, "www.something.com", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
if (hHTTPSession == NULL) {
cout << "InternetConnect() Failed - " << GetLastError() << endl;
return;
} else {
cout << "Connected to site." << endl;
}
hHTTPRequest = HttpOpenRequest(hHTTPSession, "POST", "/formtest.aspx", NULL, NULL, NULL, 0, 0);
if (hHTTPRequest == NULL) {
cout << "HttpOpenRequest() Failed - " << GetLastError() << endl;
return;
} else {
cout << "Open Request." << endl;
}
TCHAR header[] = TEXT("Content-Type: application/x-www-form-urlencoded");
TCHAR data[] = TEXT("txtsomething1=something&txtsomething2=something");
if (HttpSendRequest(hHTTPRequest, header, strlen(header), data, strlen(data))) {
cout << "Send Request successful." << endl;
} else {
cout << "HttpSendRequest() Failed - " << GetLastError() << endl;
return;
}
InternetCloseHandle(hHTTPRequest);
InternetCloseHandle(hHTTPSession);
InternetCloseHandle(hinternet);
}
That will send the request as POST'ed data to a specific page.
Thanks again for getting us going in the right direction.
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
|