Class DHTTPClient

Inherits from:
Object
Declared in:
DHTTPClient.h

Class Hierarchy

    Object
      |
      +---DHTTPClient

Class Description

The DHTTPClient class implements a HTTP client. The class does not support the POST and PUT requests. Also the responses with a chunked transfer encoding are not handled.

Example:
#include <stdio.h>
#include "ofc/DHTTPClient.h"

int main(int argc, char *argv[])
{
  DHTTPClient   *client = [DHTTPClient new];
  DURL          *url    = [DURL        new];
  DHashIterator *iter;

  [url url :"http://ofc.dvoudheusden.net/index.html"];

  printf("Send the request for a http page..\n");
  if (![client sendStartRequest :DHC_GET :url])  // send a GET for index.html
    printf("Error in sendStartRequest..\n");

  if (![client sendConnectionHeader :"close"])   // send that the connection should be closed
    printf("Error in sendConnectionHeader..\n");

  if (![client sendUserAgentHeader :"libofc"])   // send the user agent
    printf("Error in sendUserAgentHeader..\n");

  if (![client sendEndRequest])                  // send the end of the request
    printf("Error in sendEndRequest..\n");

  printf("Wait for the response of the server..\n");
  if ([client receiveReply])                     // wait for the response of the server
  {
    printf("Response reason:%d http version:%d.%d body length:%ld\n",
      [client reason], [client peerMajor], [client peerMinor], [client bodyLength]);

    iter = [client headers];                     // print the headers in the reply

    if (iter != nil)
    {
      DText *value = [iter first];

      printf("Headers in reply:\n");
      while (value != nil)
      {
        DText *key = [iter key];

        printf("%s = %s\n", [key cstring], [value cstring]);

        value = [iter next];
      }
      [iter free];
    }
    else
      printf("No headers in reply..\n");

  }
  else
    printf("Error in receiveReply..\n");

  [client free];                       // Cleanup
  [url    free];

  return 0;
}
Last modified:
16-Aug-2008 (DHTTPClient.h)

Instance Variables

private DSocket *_client
the client socket
private BOOL _shouldOpen
should the socket be opened?
private int _state
the state of the client
private DText *_server
the server host name (or proxy)
private DInetSocketAddress *_address
the address of the server (or proxy)
private int _type
the request type (DC_HEAD, DHC_GET, ..)
private int _major
the major version number (def. 1)
private int _minor
the minor version number (def. 1)
private BOOL _shouldClose
should the connection close after comm.?
private DText *_request
the request
private DData *_response
the respone
private int _respIndex
the index in the response string
private DText *_line
one line of the response
private int _reason
the received reply reason
private DText *_reasonText
the received reason text
private DHashTable *_headers
the received headers
private DData *_body
the received body in data
private BOOL _useChunked
is chunked used ?
private int _length
the length of the body
private int _peerMajor
the major version number of the peer
private int _peerMinor
the minor version number of the peer

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0