I am getting the error ‘WebException: The request timed out’ when running this script. I am new to unity/c# and have no idea why or how to fix it.
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Linq;
using System.Net;
using LitJson;
public class predictionScript : MonoBehaviour
{
public Text guess;
public Text theDate;
int daysInMonth;
int theDay;
int theMonth;
int dayOfMonth;
float percentage;
float temp;
int low;
int high;
int pop;
int autoDaysOff;
DateTime thisDay;
bool school = true;
string conString;
string foreString;
string weather;
string[] conditionsArray = { "Clear", "Overcast", "Scattered Clouds", "Mostly Cloudy", "Partly Cloudy" };
void Start()
{
using (WebClient urls = new WebClient())
{
//wunder ground urls
conString = urls.DownloadString("http://api.wunderground.com/api/"my under ground key"/conditions/q/WI/Verona.json");
foreString = urls.DownloadString("http://api.wunderground.com/api/"my under ground key"/forecast/q/WI/Verona.json");
conditionsData(conString);
forecastData(foreString);
}
}
public void conditionsData(string conString)
{
//creates jsondata object data and maps constring url
JsonData data = JsonMapper.ToObject(conString);
weather = (string)data["current_observation"]["weather"];
}
public void forecastData(string foreString)
{
//creates jsondata object data2 and maps forestring url
JsonData data2 = JsonMapper.ToObject(foreString);
//pulls probibility of precipitaion from forestring
int popData = (int)data2["forecast"]["simpleforecast"]["forecastday"][0]["pop"];
string lowData = (string)data2["forecast"]["simpleforecast"]["forecastday"][0]["low"]["fahrenheit"];
string highData = (string)data2["forecast"]["simpleforecast"]["forecastday"][0]["high"]["fahrenheit"];
low = int.Parse(lowData);
high = int.Parse(highData);
pop = popData;
}
-PS. if there is anything else I could fix please let me know.