从共享Windows托管服务器上托管的ASP.NET Web API应用程序中,Google API调用失败

时间:2018-05-20 19:02:47

标签: c# asp.net .net asp.net-web-api2 shared-hosting

我创建了一个ASP.net Web API应用程序。此应用程序有一个API,可以从我的Android应用程序接收sku Id和购买令牌,验证购买并返回适当的结果。现在,问题是,当我在本地运行我的应用程序时,它运行正常。谷歌给我回复,我可以处理它。但是当我在共享的Windows托管服务器上托管此应用程序时,此调用将失败。它只是失败了,没有错误。

这是我的Web API。

[HttpPost]
[Route("Api/Files/GetFiles")]
public HttpResponseMessage GetFiles(FileInfo fileInfo)
{
    string skuId = fileInfo.SkuId;
    string purchaseToken = fileInfo.PurchaseToken;
    ProductPurchase productPurchase = GoogleAPIConnector.GetProductPurchaseInfo(skuId, purchaseToken);
}

以下是' GetProductPurchaseInfo'功能

public static ProductPurchase GetProductPurchaseInfo(string productId, string purchaseToken)
        {
            string packageName = "my.package.name";

            string sFileContents = "my p12 file contents as a byte array";

            byte[] baFileContents = Convert.FromBase64String(sFileContents);

            var certificate = new X509Certificate2(baFileContents,
                            "notasecret",
                            X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet
                        );

            var credentials = new ServiceAccountCredential(
                    new ServiceAccountCredential.Initializer("my publisher account on google play service")
                    {
                        Scopes = new[] { AndroidPublisherService.Scope.Androidpublisher }
                    }.FromCertificate(certificate));

            var service = new AndroidPublisherService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credentials,
                ApplicationName = "my application name",
            });

            return service.Purchases.Products.Get(packageName, productId, purchaseToken).Execute();
        }

我最终试图寻找解决方案。这可能是因为在共享托管环境中禁止API调用吗?我认为这可能是唯一的原因,因为当本地运行应用程序时,此调用是成功的。或者我错过了服务器上的一些配置?

1 个答案:

答案 0 :(得分:0)

我能够通过更改我的网络托管服务提供商来解决此问题。我选择了Accuwebhosting。我使用Postman部署了我的代码,称为API,并且能够得到响应。

所以,这是GoDaddy的错。 (恨他们的另一个原因是什么?)

相关问题