CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892

    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.

  2. #2
    Join Date
    Feb 2002
    Posts
    5,757
    Post the section of code the developer is having problems with.

    Kuphryn

  3. #3
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    2,236
    When in doubt check the RFC. There might be something on w3.org too.

  4. #4
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892
    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
  •  





Click Here to Expand Forum to Full Width

Featured