【发布时间】:2017-10-25 18:17:55
【问题描述】:
我收到以下错误:“远程服务器返回错误:(401) Unauthorized”在这一行:
using (HttpWebResponse httpResponse = request.GetResponse() as HttpWebResponse) {}
完整代码如下:
string clientSecretKey = ConfigurationManager.AppSettings["ClientSecretKey"];
const string ChargeUrl = "https://api.stripe.com/v1/charges?amount={0}¤cy={1}&source={2}&description={3}";
string requestUrl = HttpUtility.UrlPathEncode(
String.Format(ChargeUrl, 1000, "usd", "tok_19xLu8HN9aKw9vrkUsflNWOI", "Test charge to text@example.com") );
HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
request.Headers.Add("Authorization", "sk_test_example");
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
using (HttpWebResponse httpResponse = request.GetResponse() as HttpWebResponse)
{/* some code */}
一开始我以为是token不能使用超过一次导致的错误,但是我改了,还是一样的错误。我不确定是什么导致了错误。
【问题讨论】:
-
消息很清楚。您的 API 密钥无效。可能是您输入了错误的密钥或未按预期发送密钥。调试您设置的 API 密钥...
-
很遗憾,API 密钥是正确的。我想问题一定是我没有把条带授权做对。
-
如果您不确定使用原始 C# 的 Stripe 调用。您应该使用一些库来简化它。不幸的是,Stripe 没有 C# 的官方库。你可以看看一些第三方libraries。
-
我忘了说我不能使用第三方库。
标签: c# stripe-payments http-status-code-401 stripe.net