#include <httpclnt.h>
Public Member Functions | |
HTTPConnection (const char *agent, const URL &url) | |
Socket & | get_socket (const AddressList &addr) |
void | close () |
string | send_request (const URL &url, const AddressList &addr, const char *verb, const char *data, size_t len, bool close_connection) |
Public Attributes | |
const char * | _agent |
URL | _url |
Private Attributes | |
INConnect * | _pConnect |
Definition at line 172 of file httpclnt.h.
XMLRPC::HTTPConnection::HTTPConnection | ( | const char * | agent, |
const URL & | url | ||
) |
Definition at line 115 of file httpclnt.cpp.
: _agent(agent),
void XMLRPC::HTTPConnection::close | ( | ) |
Definition at line 130 of file httpclnt.cpp.
{ if (_pConnect) {
Socket & XMLRPC::HTTPConnection::get_socket | ( | const AddressList & | addr ) |
Definition at line 122 of file httpclnt.cpp.
{ } Socket& HTTPConnection::get_socket(const AddressList& addr) { if (!_pConnect)
string XMLRPC::HTTPConnection::send_request | ( | const URL & | url, |
const AddressList & | addr, | ||
const char * | verb, | ||
const char * | data, | ||
size_t | len, | ||
bool | close_connection | ||
) |
Definition at line 139 of file httpclnt.cpp.
{ Socket& socket = get_socket(addr); // send the HTML request header ostringstream buffer; buffer << verb << " " << url._path << " HTTP/1.1\r\n"; buffer << "User-Agent: " << _agent << "\r\n"; buffer << "Host: " << url._hostname << ":" << url._port << "\r\n"; buffer << "Content-length: " << len << "\r\n"; buffer << "Content-type: text/xml\r\n"; // buffer << "Cache-Control: no-cache\r\n"; buffer << "\r\n"; const string& header = buffer.str(); socket.send(header.c_str(), header.length()); // send the request body socket.send(data, len); // read response line SocketReader reader(socket); char line[BUFFER_LEN]; if (reader.read_line(line, BUFFER_LEN) <= 0) throw Exception("missing HTML server response"); char version[12]; int code; char msg[BUFFER_LEN]; #ifdef __STDC_WANT_SECURE_LIB__ if (sscanf_s(line, "%s %d %s", version, _countof(version), &code, msg, _countof(msg)) != 3) #else if (sscanf(line, "%s %d %s", version, &code, msg) != 3) #endif throw Exception("invalid HTML server response"); if (code != 200) throw Exception(line); // read the response header int content_length = 0; string content_type; for(;;) { if (reader.read_line(line, BUFFER_LEN) <= 0) break; if (!_strnicmp(line, "Content-length:", 15)) content_length = atoi(line+15); else if (!_strnicmp(line, "Content-type:", 13)) content_type = line+14; else if (!_stricmp(line, "Connection: close")) close_connection = true; } if (!content_type.empty() && _strnicmp(content_type.c_str(),"text/xml",8)) { char b[BUFFER_LEN]; sprintf(b, "illegal content type: %s", content_type.c_str()); throw Exception(b); } // read the response body string ret; if (content_length) { ret.resize(content_length); reader.read(&ret.at(0), content_length); } if (close_connection)
const char* XMLRPC::HTTPConnection::_agent |
Definition at line 177 of file httpclnt.h.
INConnect* XMLRPC::HTTPConnection::_pConnect [private] |
Definition at line 183 of file httpclnt.h.
Definition at line 178 of file httpclnt.h.