We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › strange code behaviour http: client
Page Index Toggle Pages: 1
strange code behaviour http: client (Read 217 times)
strange code behaviour http: client
Jan 29th, 2009, 4:19pm
 
hi I am trying out the standard http client example, but have run into a problems. for some reason it is not picking up the url I wish, only the host: line. So I get text from Host: www.processing.org\n\n or a 403 if I don't include a website in the Host: line.

cheers,
Brian


import processing.net.*;

Client c;
String data;

void setup() {
 size(200, 200);
 background(50);
 fill(200);
 c = new Client(this, "www.processing.org", 80); // Connect to server on port 80
 c.write("GET / HTTP/1.1\n"); // Use the HTTP "GET" command to ask for a Web page
 c.write("Host: www.processing.org\n\n"); // Be polite and say who we are
}

void draw() {
 if (c.available() > 0) { // If there's incoming data from the client...
   data = c.readString(); // ...then grab it and print it
   println(data);
 }
}
Re: strange code behaviour http: client
Reply #1 - Jan 29th, 2009, 5:50pm
 
Mmm, the example is a bit misleading.
In theory, end-of-line markers should be \r\n, not just \n.
And Host: indicates which server we try to reach, not "who we are".
The difference with the Client constructor is that the latter uses the IP address of the server (directly given or after DNS conversion) while the former (the Host) indicates which server to reach behind this IP address (eg. in case of shared hosting or load-balancing, etc.).
Page Index Toggle Pages: 1