407 Proxy Authentication Error

  • 1
  • Problem
  • Updated 2 years ago
  • (Edited)

I have received my API and am attempting to pull the current weather data using C# in VS2015 (see code below). When I get to the cli.downloadstring line it is throwing the error 'The remote server returned an error (407) proxy authentication required'. But if I put the url directly into the IE browser I get the data in xml format. Why is it not working through the webclient?

Code:

        static void Main(string[] args)
        {
            //Start program
            string wunderground_key = "###############";
            parse("http://api.wunderground.com/api/"; + wunderground_key + "/conditions/q/VA/Roanoke.xml");
        }

        //Takes a url request to wunderground, parses it, and displays the data.
        private static void parse(string input_xml)
        {
            //Variables
            string place = "";
            string obs_time = "";
            string weather1 = "";

            string ErrorMsg = "";

            var cli = new WebClient();

            try
            {
                string weather = cli.DownloadString(input_xml);

                using (XmlReader reader = XmlReader.Create(new StringReader(weather)))
                {
                    // Parse the file and display each of the nodes.
                    while (reader.Read())
                    {
                        switch (reader.NodeType)
                        {
                            case XmlNodeType.Element:
                                if (reader.Name.Equals("full"))
                                {
                                    reader.Read();
                                    place = reader.Value;
                                }
                                else if (reader.Name.Equals("observation_time"))
                                {
                                    reader.Read();
                                    obs_time = reader.Value;
                                }
                                else if (reader.Name.Equals("weather"))
                                {
                                    reader.Read();
                                    weather1 = reader.Value;
                                }

                                break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMsg = ex.Message;
                throw;
            }


Photo of John Baldwin

John Baldwin

  • 3 Posts
  • 0 Reply Likes

Posted 2 years ago

  • 1
Photo of John Baldwin

John Baldwin

  • 3 Posts
  • 0 Reply Likes
I figured it out. I had to set up code to go through our proxy. Once I did that it worked fine.