0

I have an error when trying to hit a web services that gives me weather updates. I used to be able to hit it using visual webpart in SP2010. Now I get the exception: an exception occurred during a webclient request. Inner exception: "The ServicePointManager does not support proxies with the https scheme.". when I look into the url of the web api it has changed from http proxy to https, but I would like to know how I would force my app to accept the https scheme? here is bit of my code

protected void GetWeatherInfo(string url)
    {
        //txtCity.Text = "Cape Town";
        // var city = "Cape Town";
        //string appId = "<App Id>";
        string url1 = string.Format(url);
        using (WebClient client = new WebClient())
        {
            WebProxy proxyObj = new WebProxy(url);

            proxyObj.Credentials = CredentialCache.DefaultCredentials;


            client.Proxy = proxyObj;
            try
            {
                client.Encoding = System.Text.Encoding.UTF8;
                string json = client.DownloadString(url);

                WeatherInfo weatherInfo = (new JavaScriptSerializer()).Deserialize<WeatherInfo>(json);
                lblCity_Country.Text = weatherInfo.city.name + "," + weatherInfo.city.country;
                imgCountryFlag.ImageUrl = string.Format("http://openweathermap.org/images/flags/{0}.png", weatherInfo.city.country.ToLower());
                lblDescription.Text = weatherInfo.list[0].weather[0].description;
                imgWeatherIcon.ImageUrl = string.Format("http://openweathermap.org/img/w/{0}.png", weatherInfo.list[0].weather[0].icon);
                lblTempMin.Text = string.Format("{0}°С", Math.Round(weatherInfo.list[0].temp.min, 1));
                lblTempMax.Text = string.Format("{0}°С", Math.Round(weatherInfo.list[0].temp.max, 1));
                lblTempDay.Text = string.Format("{0}°С", Math.Round(weatherInfo.list[0].temp.day, 1));
                lblTempNight.Text = string.Format("{0}°С", Math.Round(weatherInfo.list[0].temp.night, 1));
                lblHumidity.Text = weatherInfo.list[0].humidity.ToString();
                tblWeather.Visible = true;
            }
            catch (Exception ex)
            {
                string excep = ex.Message;
                Console.WriteLine(ex.Message.ToString());
            }

        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.