Thread: HTTP Request/Response Libraries?

  1. #1
    Registered User
    Join Date
    Dec 2008
    Location
    Birmingham, UK.
    Posts
    14

    HTTP Request/Response Libraries?

    Are there any free libraries available for performing HTTP requests and responses?

  2. #2
    Registered User
    Join Date
    Dec 2008
    Location
    Birmingham, UK.
    Posts
    14
    Ah I think libcurl might be useful. I only need it to get the content from a page. It's for a data harvester.

  3. #3
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    If you only need source you can save it to a file:
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <windows.h>
    
    #include <urlmon.h>
    
    /* Or link to the library via the means you normally would do */
    #pragma comment( lib, "urlmon.lib" )
    
    int main() {
      char url[] = "http://www.google.com";
      char sourceFile[MAX_PATH];
    
      HRESULT hr = URLDownloadToCacheFile(0, url,
        sourceFile, MAX_PATH, 0, 0);
    
      if ( hr == S_OK ) {
        /* Read the file at sourceFile */
        printf( "Source located at: %s\n", sourceFile );
      }
    
      return 0;
    }
    This works with visual studio. What compiler do you use?
    [edit] Sorry, first code I posted was C++
    Last edited by twomers; 12-24-2008 at 06:44 AM.

  4. #4
    Registered User
    Join Date
    Jun 2008
    Posts
    266
    Quote Originally Posted by twomers View Post
    If you only need source you can save it to a file:
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <windows.h>
    
    #include <urlmon.h>
    
    /* Or link to the library via the means you normally would do */
    #pragma comment( lib, "urlmon.lib" )
    
    int main() {
      char url[] = "http://www.google.com";
      char sourceFile[MAX_PATH];
    
      HRESULT hr = URLDownloadToCacheFile(0, url,
        sourceFile, MAX_PATH, 0, 0);
    
      if ( hr == S_OK ) {
        /* Read the file at sourceFile */
        printf( "Source located at: %s\n", sourceFile );
      }
    
      return 0;
    }
    This works with visual studio. What compiler do you use?
    [edit] Sorry, first code I posted was C++
    You wouldn't happen to have a Linux equivalent for this would you? That would save me about 3 days of Google searching...
    Fried chicken for everybody!
    -Kernel Sanders

  5. #5
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Sorry. Maybe someone else can help.

    Though libcurl is easy to work with. And if your 'data harvester' needs to get fancier, ie using cookie manipulation, multi threading, etc, it'll be easier to do it with libcurl than other high level functions, I think.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Moved to Networking/Device Communication forum.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Like jamesjeffery said, libcurl is the way to go. Here's the tutorial.

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > You wouldn't happen to have a Linux equivalent for this would you?
    Sure, either use libcurl as mentioned above or call `wget`

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error stop Http Listener
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 06-04-2008, 02:14 AM
  2. my HTTP request handler code correct?
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 04-25-2008, 04:01 AM
  3. C# HTTP request/response
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 04-02-2008, 06:00 AM
  4. MinGW thread-safe runtime libraries
    By Mario F. in forum C++ Programming
    Replies: 3
    Last Post: 08-21-2006, 08:15 AM
  5. Writing all HTTP requests from a website to a log file
    By goomyman in forum C# Programming
    Replies: 1
    Last Post: 07-29-2005, 09:18 AM