We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm gathering daily weather forecast temperature data from 3 sites/pages via the http.requests library. It works fine on the 2 url's that are commented out in my code, but not on the third. Any idea why?
import http.requests.*;
public void setup()
{
size(400,400);
smooth();
//GetRequest get = new GetRequest("http://" + "forecast.weather.gov/MapClick.php?CityName=State+College&state=PA&site=CTP&textField1=40.7906&textField2=-77.8579");
//GetRequest get = new GetRequest("http://" + "api.wunderground.com/api/dc43c0b770a7c1e0/forecast/q/PA/State_College.json");
GetRequest get = new GetRequest("http://" + "www.accuweather.com/en/us/state-college-pa/16801/daily-weather-forecast/6787_pc");
get.send();
println("Reponse Content: " + get.getContent());
println("Reponse Content-Length Header: " + get.getHeader("Content-Length"));
}
Thanks for any suggestions you may have,
Wade
Answers
If you put the link in your browser, what do you get? Is this an API to request data?
Kf
That link redirects to https for me. Are you sure the link shouldn't be https or the library supports cross-protocol redirects?
kfrajer: the url takes you to a web page; it's not an API access. I do use an API for the one page (Weather Channel) in my code above; it works fine.
Neilcsmith: good catch... my url should be https; and I use the https url in my code. My mistake: I C&P'ed a test url in my post; but it still doesn't work: I get "java.net.SocketTimeoutException: Read timed out".
I don't know if the library supports cross-protocol redirects; I don't know what that means either. I'll see if I can get an answer to that from the library's creator, Daniel Shiffman.
Thanks for your replies,
You need to check the API of the third link. Browsing over the site, I found the following link: https://developer.accuweather.com/getting-started
Now, I tried your first link and you are getting the raw html response from the server. You can process this data, but that is not what I consider a proper way to request data.
I check your second link and that looks better. You get a json response which you can process with a JSON object in Processing. For examples of API request posts, check:
Related to:
it seems you are using some code from other sources. It is convenient if you provide this sources.
Also consider checking the Yahoo weather library. You can install it easily using the Contribution Manager in the PDE. Go to Sketch>>Add library And then go to the end where you will find it. After you install it, you can go to Files>>Examples then to Contributed Libraries>> YahooWeather to see the library in action.
Kf
Java's built in support for reading from URL's can follow redirects, but not across different protocols - eg. from http to https. This was rejected for security reasons. So unless this library has been written to do this for you, it won't work.