gpt4 book ai didi

c# - 400 : bad request

转载 作者:行者123 更新时间:2023-12-03 00:52:48 25 4
gpt4 key购买 nike

我正在使用 csmanage 访问 Azure 管理 API。这是我的代码:

    private const string subscriberID = "<id>";

static void Main(string[] args)
{
// The thumbprint value of the management certificate.
// You must replace the string with the thumbprint of a
// management certificate associated with your subscription.
string certThumbprint = "<thumbprint>";

// Create a reference to the My certificate store.
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);

// Try to open the store.
try
{
certStore.Open(OpenFlags.ReadOnly);
}
catch (Exception e)
{
throw;
}

// Find the certificate that matches the thumbprint.
X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, certThumbprint, false);
certStore.Close();

// Check to see if our certificate was added to the collection. If no, throw an error, if yes, create a certificate using it.
if (0 == certCollection.Count)
{
throw new Exception("Error: No certificate found containing thumbprint " + certThumbprint);
}

// Create an X509Certificate2 object using our matching certificate.
X509Certificate2 certificate = certCollection[0];



var serviceManagment = ServiceManagementHelper.CreateServiceManagementChannel("WindowsAzureEndPoint", new X509Certificate2(certificate));
var x = serviceManagment.ListHostedServices(subscriberID);

foreach (HostedService s in x)
{
Console.WriteLine(s.ServiceName);
}
}

这在控制台应用程序中工作得很好。但是,当我在 WCF 项目(作为服务实现)中执行完全相同的代码时,我得到 400 - Bad Request 结果。

什么可能导致此错误?

最佳答案

这并不是一个真正的答案,但您可以做的一件事是通过使用类似于以下的代码捕获 Web 异常来查看有关 400 错误的更多详细信息:

    catch (WebException webEx)
{
string errorDetail = string.Empty;
using (StreamReader streamReader = new StreamReader(webEx.Response.GetResponseStream(), true))
{
errorDetail = streamReader.ReadToEnd();
}
}

此处 errorDetail 将是一个 XML,它应该为您提供更多信息。

关于c# - 400 : bad request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15636260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com