0

我正在访问 Rackspace Cloud API。

我有一个 api 调用可以在 rackspace 云上对我进行身份验证。

该方法完美运行,但是,我不时随机收到此异常:

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);
    }
}
4

1 回答 1

0

这听起来确实像是 DNS 故障。您可以将您的机器配置为使用Google DNS 服务器并重试吗?

于 2015-01-12T16:38:59.603 回答