1

I have created code which downloads data by using API. Everything works properly locally but when I moved it into our server I am getting error:

System.Net.WebException: The remote name could not be resolved: 'api.blabla.com'     at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)     at System.Net.HttpWebRequest.GetRequestStream()

Below code I am using:

private static void Authenticate_GroupLevel(string clientID, string clientSecret, out string accessToken, out string enterprise)
    {
        accessToken = "";
        enterprise = "";

        try
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.bluejeans.com/oauth2/token");
            //httpWebRequest.ContentType = "text/json";
            httpWebRequest.ContentType = "text/plain";
            httpWebRequest.Method = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string credentials = "{\"grant_type\":\"client_credentials\",\"client_id\":\"" + clientID + "\",\"client_secret\":\"" + clientSecret + "\"}";
                //Console.WriteLine(credentials);
                streamWriter.Write(credentials);
                streamWriter.Flush();
                streamWriter.Close();

                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result_JSON = streamReader.ReadToEnd();
                    streamReader.Close();
                    string result_XMLString = @"{'?xml': {'@version': '1.0', '@standalone': 'no'}, 'root':  [" + result_JSON + @"]}";
                    // convert JSON to XML
                    XmlDocument resultXML = JsonConvert.DeserializeXmlNode(result_XMLString);
                    //Console.WriteLine(resultXML.OuterXml);
                    accessToken = resultXML.DocumentElement.SelectSingleNode("/root/access_token").InnerText;
                    enterprise = resultXML.DocumentElement.SelectSingleNode("/root/scope/enterprise").InnerText;

                }
            }
        }
        catch (Exception ex)
        {
            LogErrors(ex.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name.ToString());
        }

    }

Can anybody help me resolve this issue?

ironcurtain
  • 650
  • 9
  • 35
  • 1
    The DNS lookup is failing on the server you have deployed to for your endpoint URI. – Ben Robinson Sep 16 '14 at 16:12
  • @BenRobinson What does it mean exactly? Can it be resolved? It works locally but not in the server. – ironcurtain Sep 16 '14 at 16:29
  • It appears to be a network issue, i would speak to whoever is reposible for maintaining your server, the error is saying it cannot resolve `api.bluejeans.com` or whatever Uri you are using in your production code. – Ben Robinson Sep 16 '14 at 16:32
  • I am the person who maintains the server... – ironcurtain Sep 16 '14 at 16:54
  • I searched the internet to resolve this issue but everywhere I found the same answers: DNS lookup failing (this can be found in the error description), network issue (what kind of issue?). I would like to know where to start searching the root cause of the issue. – ironcurtain Sep 16 '14 at 17:20
  • Do you have a DNS server in your network? Try `nslookup api.blabla.com`. Next step will be to allow outgoing traffic on your firewall. – Jan Zahradník Sep 16 '14 at 18:15
  • @JanZahradník When I run nslookup either loccally or on the server it returns: Non-existent domain error. – ironcurtain Sep 18 '14 at 10:15
  • Did you tried with your real testing domain? I've used DNS from the exception and now I found that in the code you use different url – Jan Zahradník Sep 18 '14 at 11:12
  • @JanZahradník I used: api.bluejeans.com for testing. – ironcurtain Sep 22 '14 at 17:53

0 Answers0