' identity.api.rackspacecloud.com'随机抛出'远程名称无法解析'例外

时间:2015-01-12 10:43:57

标签: dotnet-httpclient rackspace-cloud rackspace rackspace-cloudfiles

我正在访问Rackspace Cloud API。

我有一个api电话,它在架空云上验证我。

该方法运行良好,但是,我不时会得到这个例外,随机

The remote name could not be resolved: 'identity.api.rackspacecloud.com'

当我没有得到此异常时,该方法返回预期的结果,应该是。

为什么会这样做有什么具体原因?

这是我的.net代码:

private async Task<XDocument> AuthenticateAsync()
{
    XNamespace ns = "http://docs.rackspace.com/identity/api/ext/RAX-KSKEY/v1.0";

    XDocument doc =
        new XDocument(
            new XDeclaration("1.0", "UTF-8", "Yes"),
            new XElement("auth",
                new XElement(ns + "apiKeyCredentials",
                    new XAttribute("username", "the userName"),
                    new XAttribute("apiKey", "the apiKey")
                )
            )
        );

    using (HttpClient client = new HttpClient())
    {
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));

        StringContent content = new StringContent(doc.ToString(), Encoding.UTF8, "application/xml");

        // i randomly get "The remote name could not be resolved" exception
        HttpResponseMessage response = await client.PostAsync("https://identity.api.rackspacecloud.com/v2.0/tokens", content);
        response.EnsureSuccessStatusCode();

        string stringResponse = await response.Content.ReadAsStringAsync();
        return XDocument.Parse(stringResponse);
    }
}

1 个答案:

答案 0 :(得分:0)

这当然听起来像DNS故障。您是否可以将机器配置为使用Google DNS servers并重试?