WxHTTP
Jump to navigation
Jump to search
wxHTTP Functions Missing from Docs
Functions found in src/common/http.cpp that you need to know about but that arn't documented in <wxref class="wxHTTP" method=""></wxref>.
wxHTTP::Abort
bool Abort(void)
Aborts an active trrancfure by closing the connection.
wxHTTP::Connect
bool Connect(wxSockAddress& addr, bool WXUNUSED(wait))
bool Connect(const wxString& host, unsigned short port)
These do not make an actual connection to a server but simple tell wxHTTP about the server you want to request pages from.
wxHTTP::SetPostBuffer
void SetPostBuffer(const wxString& post_buf)
Set the data to be posted to the server.
wxHTTP::GetContentType
wxString GetContentType()
Get the "Content-Type" header returned by the server.
wxHTTP::SetProxyMode
void SetProxyMode(bool on)
Set whether or not to use a proxy.
wxHTTP::ClearHeaders
void ClearHeaders()
Removes all headers.
wxHTTP::GetInputStream
wxInputStream *GetInputStream(const wxString& path)
Get a page from the server specified by the last call to Connect(...). Path is path to a resource on the server not a full URL. Note: You must call one of the Connect functions at least once before using this function or the result will be NULL.
Basic Usage
wxHTTP get;
wxString res;
get.SetHeader( "User-Agent", "wxHTTP" );
get.SetUser( "annon" );
get.SetPassword( "" );
get.Connect( "www.google.com", 80 );
// just grab the root document. index.html, default.asp, etc. the server will determine what it sould be.
wxInputStream* resStream = get.GetInputStream( "/" );
wxLogVerbose( wxString(" GetInputStream: ") << get.GetResponse() << "-" << ((resStream)?"OK " :"FAILURE ") << get.GetError() );
do
{
size_t len = 1024;
char buff[len];
resStream->Read( buff, len );
res.Append( buff, resStream->LastRead() );
} while( resStream->LastRead() > 0 );
wxLogVerbose( wxString(" returned document length: ") << res.Length() );