Pages: [1]   Go Down
Author Topic: Heroku Request  (Read 419 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am attempting to grab some information off of a Heroku app I set up, however I am hit with Heroku's 404 page. I tested a similar request with a simple Python script, which worked fine.

The Arduino Code:
Code:
if (!client.connected()) {
    Serial.println("connecting...");
   
    if (client.connect(serverName, 80)) {
      Serial.println("connected");
     
      // Make a HTTP request
      client.println("GET / HTTP/1.0");
      client.println();
     
      while (!client.available());
     
      // If data can be read from te server, print it
      while (client.available()) {
        char c = client.read();
        Serial.print(c);
      }
     
      Serial.println("Done");
     
      client.stop();
    } else {
      // If you didn't get a connection to the server:
      Serial.println("connection failed");
    }
  }

For the record, as this is different from the example, you may question whether the altered algorithm works. It does, the exact same thing sending a request to Google works fine.

Python Code:
Code:
import httplib

h = httplib.HTTPConnection("ruby-coffee-maker.herokuapp.com")

h.request("GET", "/")

r = h.getresponse()
data = r.read()

print r.status, r.reason, "\"" + data + "\""

h.close()

Thanks in advance for any help!
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is necessary to send a Host header so Heroku knows which app to route your request to:

From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html:
Code:
       GET /pub/WWW/ HTTP/1.1
       Host: www.w3.org

-br
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
      client.println("GET / HTTP/1.0");
You are asking for an unnamed script at the root of the unnamed server to be executed.

Without knowing what server you are pointing the request to, all we can surmise is that you are doing it wrong.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@billroy: I tried replacing "GET /" with "GET /pub/WWW/", to no avail. Also, Heroku does not support HTTP 1.1.

@PaulS: My bad, I left that bit out. Here you are:

Code:
char serverName[] = "ruby-coffee-maker.herokuapp.com";

I was a bit concerned that "-" was an illegal character, but changing it on the server side to not have hyphens yielded a net gain of nada.
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1. That was an example from the link I provided.  It is necessary to adapt it to your code.

2. You need a Host: header.  Did you try that?


-br
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@billroy: I tried a few Host: headers, which still yielded 404s. What would the header code look like for this case?
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you consider trying the Heroku application hostname you are attempting to connect to?

-br
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@ billroy: I tried it to no avail.
Logged

Pages: [1]   Go Up
Jump to: