-->
Page 1 of 4

Function to fetch a web page and return a string?

PostPosted: Tue Aug 25, 2015 3:25 pm
by Mmiscool
hello.

I am attempting to find a function that will fetch a web page and return a sting.

Some thing like
Code: Select allString FetchURL(String WebAddress, TimeOut){
...
}


Some one must have some thing pre-built to do this task. Searched the forum for about 20 minuets looking but nothing was very clear about fetching a url.

Re: Function to fetch a web page and return a string?

PostPosted: Tue Aug 25, 2015 4:33 pm
by martinayotte
Here is some snippet of code that get external IP address, just by changing the site and URL will fetch almost anything you want to.

Code: Select all  WiFiClient client;
  if (!client.connect("api.ipify.org", 80)) {
    p.println("Failed to connect with 'api.ipify.org' !");
  }
  else {
    client.print("GET /?format=json HTTP/1.1\r\nHost: api.ipify.org\r\n\r\n");
    delay(100); 
    String = "";
    while(client.available()){
      str += client.read();
    }         
    Serial.print(str);
  } 

Re: Function to fetch a web page and return a string?

PostPosted: Tue Aug 25, 2015 4:45 pm
by Mmiscool
Now thats awesome. Thanks

Re: Function to fetch a web page and return a string?

PostPosted: Thu Aug 27, 2015 8:33 pm
by Mmiscool
Just picked this back up after a few days. Not quite ubderstaning the code. It seems like the server and the server url are not the same.

So to make this in to a function the url will have to be parsed fortheserver and for the actual url request.
Is this a correct asumption.

I find it hard to belive that there is not an existing function to do this. :?: