HTTP with Portable Component Library

This is a discussion on HTTP with Portable Component Library within the C++ Programming forums, part of the General Programming Boards category; I'm experimenting with new Portable C++ Component Library using classes for HTTP connection. HTTP connecting works fine, but I have ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Europe/Belgrade
    Posts
    78

    HTTP with Portable Component Library

    I'm experimenting with new Portable C++ Component Library using classes for HTTP connection.
    HTTP connecting works fine, but I have problems sending data using get/post method. I'm trying to send login data to my site using post method, but Apache doesn't receive them in correct format. Message header is corrupted, some weird symbols occurs.

    Code:
      try
      {
    // making connection and sending parameters
        HTTPClientSession session("mysite.com");
        HTTPRequest req(HTTPRequest::HTTP_POST, "/console/index.php");
        req.set("username", "karas");
        req.set("password", "blabla");
        session.sendRequest(req);
    
        HTTPResponse resp;
        istream& rs =  session.receiveResponse(resp);
        StreamCopier::copyStream(rs, cout);// prints response message body
      }
      catch (Exception& exc)
      {
        cout << exc.displayText() << endl;
      }
    Parameters username and password are sent but there are also symbols in the header which aren't text. Someone has idea what could be wrong: is it library, bad data encoding, something else?
    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Jan 2006
    Location
    Europe/Belgrade
    Posts
    78
    Solved, here's the code if someone needs it:

    Code:
    // set URL
    URI uri("http://mysite.com/karas/login.php?user=karas&pass=blah");
    string path(uri.getPathAndQuery());
    if (path.empty())
      path = "/";
    
    // set connection
    HTTPClientSession session(uri.getHost(), uri.getPort());
    HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1);
    session.sendRequest(req);
    
    // print response to STDOUT
    HTTPResponse resp;
    istream& rs =  session.receiveResponse(resp);
    StreamCopier::copyStream(rs, cout);
    Instead of C strings class string is used beacuse of references.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. looking for small freeware library that support http connections
    By umen242 in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-23-2008, 04:21 AM
  2. Replies: 3
    Last Post: 09-01-2005, 12:47 PM
  3. What's a portable graphics library?
    By dwks in forum Game Programming
    Replies: 2
    Last Post: 07-06-2005, 04:13 AM
  4. Portable Audio Library
    By CornedBee in forum C++ Programming
    Replies: 2
    Last Post: 05-19-2005, 03:09 AM
  5. http application library known ?
    By chris78 in forum Linux Programming
    Replies: 3
    Last Post: 04-28-2004, 11:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21