我收到以下错误:“远程服务器返回错误:(401)未经授权”在这一行:
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不能使用超过一次导致的错误,但是我改了,还是一样的错误。我不确定是什么导致了错误。