我正在尝试将PayPal付款纳入我们的项目,但我现在失败了。
基本上,第一步是获取访问令牌请求和响应,我正在尝试使用WebRequest,但它向我吐出401。
按照以下说明进行操作:https://developer.paypal.com/docs/integration/direct/make-your-first-call/
以下是代码:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
WebRequest request = WebRequest.Create("https://api.sandbox.paypal.com/v1/oauth2/token");
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.Credentials = new NetworkCredential("client_id", "secret");
request.PreAuthenticate = true;
string body = "grant_type=client_credentials";
byte[] buffer = Encoding.UTF8.GetBytes(body);
request.ContentLength = buffer.LongLength;
var reqStr = request.GetRequestStream();
reqStr.Write(buffer, 0, buffer.Length);
reqStr.Close();
WebResponse response = request.GetResponse();
当然, client_id 和秘密会被代码中的实际值替换:)
感谢您的帮助!
答案 0 :(得分:0)