Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Web or HttpClient example?
Re: Web or HttpClient example? [message #8222 is a reply to message #8208] Tue, 20 February 2007 21:14 Go to previous messageGo to previous message
rylek is currently offline  rylek
Messages: 79
Registered: November 2005
Member
Hello there!

I've made a very simple example (means I've put it in the 'examples' nest) with a suprising name "httpcli" which demonstrates basic use of the HttpClient. It's a console application which processes each of its commandline arguments as an URL, downloads the given page and displays its contents on the standard output. If you don't want to wait until next distribution and are reluctant to download it from our live UVS repository, here you are, just copy the folowing source into a file and add the Web package.

Regards

Tomas

#include <Web/Web.h>

using namespace Upp;

static String DumpSpecial(String s)
{
	String out;
	for(const char *p = s.Begin(), *e = s.End(); p < e; p++)
		if((byte)*p >= ' ' && *p != '\xFF')
			out.Cat(*p);
		else {
			switch(*p) {
				case '\a': out.Cat("[\\a]"); break;
				case '\b': out.Cat("[\\b]"); break;
				case '\f': out.Cat("[\\f]"); break;
				case '\v': out.Cat("[\\v]"); break;
				case '\t': out.Cat("[\\t]"); break;
				case '\r': out.Cat("[\\r]"); break;
				case '\n': out.Cat("[\\n]\n"); break;
				default:   out.Cat(NFormat("[\\x%02x", (byte)*p)); break;
			}
		}
	return out;
}

CONSOLE_APP_MAIN
{
	const Vector<String>& cmdline = CommandLine();
	for(int i = 0; i < cmdline.GetCount(); i++) {
		String proxy;
		if(*cmdline[i] == ':' && i + 1 < cmdline.GetCount())
			proxy = cmdline[i++].Mid(1);
		String url = cmdline[i];
		puts(url);
		fflush(stdout);
		HttpClient client;
		client.URL(url);
		client.Proxy(proxy);
		String content = client.ExecuteRedirect();
		puts("[error] " + Nvl(client.GetError(), "OK (no error)"));
		puts(NFormat("[status %d] %s\n", client.GetStatusCode(), client.GetStatusLine()));
		puts(NFormat("[headers] (%d bytes)\n%s", client.GetHeaders().GetLength(), DumpSpecial(client.GetHeaders())));
		puts(NFormat("[content] (%d bytes)\n%s", content.GetLength(), DumpSpecial(content)));
		fflush(stdout);
	}
}

[Updated on: Tue, 20 February 2007 21:14]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Apps might need to be recompiled after libnotify update
Next Topic: XmlRpc Bugfixes
Goto Forum:
  


Current Time: Sat Apr 20 13:30:40 CEST 2024

Total time taken to generate the page: 0.03247 seconds