Issues Connecting Ethernet Shield through a Proxy

Hi all !

I am currently trying to set up a printer connected to a server following this tutuorial :

The original sketch is:

The issue is i'm trying to connect from a university where they use a proxy (without authentification).
So I tried to modify the sketch following the advices given here: http://forum.arduino.cc/index.php/topic,158690.0.html

Which led to this modification:

  debug2("Attempting to connect to ", host);
  if (client.connect("proxy.noc.titech.ac.jp", 3128)) {
    digitalWrite(downloadLED, HIGH);
    client.print("GET http://printer.gofreerange.com"); client.print("/printer/"); client.print(printerId); client.println(" HTTP/1.0");
    client.print("Host: "); client.print(host); client.print(":"); client.println(port);
    client.flush();
    client.print("Accept: application/vnd.freerange.printer."); client.println(printerType);
    client.print("X-Printer-Version: "); client.println(sketchVersion);
    client.println();
    boolean parsingHeader = true;

    while(client.connected()) {
      while(client.available()) {
        if (parsingHeader) {
          client.find((char*)"HTTP/1.1 ");
          char statusCode[] = "xxx";
          client.readBytes(statusCode, 3);
          statusOk = (strcmp(statusCode, "200") == 0);
          client.find((char*)"Content-Length: ");
          char c;
          while (isdigit(c = client.read())) {
            content_length = content_length*10 + (c - '0');
          }
          debug2("Content length: ", content_length);
          client.find((char*)"\n\r\n"); // the first \r may already have been read above
          parsingHeader = false;
        } else {
          cache.write(client.read());
          length++;
        }
      }
      debug("Waiting for data");
    }

    debug("Server disconnected");
    digitalWrite(downloadLED, LOW);
    // Close the connection, and flush any unwritten bytes to the cache.
    client.stop();
    cache.seek(0);

However I'm still not able to make a full connection:
My printer is detected by the server however it seems that I do not receive any data.

Here are my proxy settings: ![](http://)

Are there other part of the code that I should modify ?
I would be forever grateful if you guys could help me on this one. I spent countless of hours trying to figure out why is doesn't work.
I'm not sure if I gave all the needed info so if you need something, i would be glad to send it to you.
Thank you in advance !!

Megabouda

Sorry, here are my proxy configs :

If you are connecting to the printer, then just read the response it sends first, just to see what it is sending. Replace "printerId" with the printerid.

     client.println("GET http://printer.gofreerange.com/printer/printerId HTTP/1.1");
    client.println("Host: printer.gofreerange.com");
    client.println("Connection: close\r\n");

    while(client.connected()) {
      while(client.available()) {
         char c = client.read();
         Serial.print(c);
      }
    }
    debug("Server disconnected");
    digitalWrite(downloadLED, LOW);
    // Close the connection, and flush any unwritten bytes to the cache.
    client.stop();

edit: I redid your request to simplify it a bit.

    client.print("GET http://printer.gofreerange.com"); client.print("/printer/"); client.print(printerId); client.println(" HTTP/1.0");

The protocol and server names are NOT part of the GET request.

The protocol and server names are NOT part of the GET request.

They are if you are using a proxy.
http://forum.arduino.cc/index.php?topic=158690.msg1188318#msg1188318

Thank you for the replies!

So I tryed your simplified request. Here is what I get in the serial:

1 ID: 7m1j0q4t2a8p4v0i
1499: ID: 7m1j0q4t2a8p4v0i
3084: IP: 192.168.11.8
3095: Attempting to connect to printer.gofreerange.com
35315: Couldn't connect
36316: Bytes: 0
36316: Duration: 33231
46324: Attempting to connect to printer.gofreerange.com
connected to proxy
HTTP/1.0 200 OK
Date: Mon, 09 Sep 2013 13:54:16 GMT
Status: 200 OK
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Content-Type: text/html;charset=utf-8
Content-Length: 0
Via: 1.1 printer.gofreerange.com
Vary: Accept-Encoding
X-Cache: MISS from proxy.noc.titech.ac.jp
X-Cache-Lookup: MISS from proxy.noc.titech.ac.jp:3128
Connection: close

47312: Server disconnected
47343: Response code != 200
48372: Bytes: 0
48372: Duration: 2055

"Connected to proxy" comes from this line I added:
if (client.connect("proxy.noc.titech.ac.jp", 3128)) {
Serial.println("connected to proxy");

So I tryed my code with the Get request wtitten like that:
client.println("GET http://printer.gofreerange.com/printer/printerId HTTP/1.1");
With HTTP/1.0 changed to HTTP/1.1

This is my serial:

9071499: ID: 7m1j0q4t2a8p4v0i
3086: IP: 192.168.11.8
3098: Attempting to connect to printer.gofreerange.com
connected to proxy
4585: Waiting for data
4585: Waiting for data
4586: Waiting for data
4606: Waiting for data
4632: Waiting for data
4657: Waiting for data
4682: Waiting for data
4707: Waiting for data
4731: Waiting for data
4757: Waiting for data
4782: Waiting for data
4806: Waiting for data
4832: Waiting for data
4856: Waiting for data
7931: Content length: 0
8931: Waiting for data

and then "Waiting for data" keeps on spawning until a very far "server disconnected"...
Either way, the ethernet shield still cant connect correctly..

SuperTim, how can I read what my printer is sending?
I hope these Serial Outputs are useful yo you.

Thanks for Helping

Up. If someone can help, please do :roll_eyes:
Thank youu

Did you replace printerId with your printer ID? This link won't work.
http://printer.gofreerange.com/printer/printerId
Did you try that link with your web browser?

Yeah sorry it wasn't clear on my reply but yes I tried with printerId replaced by the actual ID of the printer. No results :frowning:
In the browser the link downloads a Zero bytes file. Try it by yourself:
http://printer.gofreerange.com/printer/7m1j0q4t2a8p4v0i

Same here without a proxy, so your issue connecting through a proxy is solved. Now you must get the printer part debugged.

Is it solved ?
The link works on my internet browser ok, but my arduino ethernet shield still doens't receive any data from the server..

This gives me a download with nothing in it using both IE and Chrome.
http://printer.gofreerange.com/printer/7m1j0q4t2a8p4v0i
I can't tell what is happening on the printer end, but it isn't a webpage.