【问题标题】:Stripe Authentication条带身份验证
【发布时间】:2012-06-04 08:06:53
【问题描述】:

我无法在 stripe.com 中进行身份验证 - 使用基本身份验证

public class Str extends HttpServlet {


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter pw=response.getWriter();
        pw.println("Hello World");
        HttpClient client= new HttpClient();
        String req="https://api.stripe.com/";
        client.getParams().setAuthenticationPreemptive(true);
        client.getState().setCredentials(new AuthScope(req, 443, null),  new UsernamePasswordCredentials("<api-key>"));
        client.getHostConfiguration().setHost(req, 443, "https");

        PostMethod post= new PostMethod("https://api.stripe.com/v1/charges/");
        //post.addParameter("id", "<id>");
        int status=client.executeMethod(post);
        pw.println(status);



    }


}

我正在展示我的代码...我使用 HTTP Basic Auth 向 stripe.com 提供用户凭据

【问题讨论】:

  • 当你尝试时会发生什么?
  • 它说没有找到默认凭据..并且身份验证失败
  • 为什么不使用 Stripe Java 绑定? stripe.com/docs/libraries

标签: authentication stripe-payments


【解决方案1】:

试试:new UsernamePasswordCredentials("&lt;api-key&gt;", "")

【讨论】:

    【解决方案2】:

    希望这会对你有所帮助。

    这里的API_KEY表示秘钥

    HttpResponse httpResponse;
    String request ='card[number]='+card_name+'&card[exp_year]='+card_exp_year+'&card[exp_month]='+card_exp_month+'&card[cvc]='+card_cvv+'&amount='+amount+ '&currency='+currency;
    Http httpObject = new Http();
    HttpRequest httpRequest = new HttpRequest();
    httpRequest.setEndpoint(sHttpEndPoint);
    httpRequest.setMethod('POST');
    Blob headerValue = Blob.valueOf(API_KEY + ':');
    String authorizationHeader = 'BASIC ' +
    EncodingUtil.base64Encode(headerValue);
    httpRequest.setHeader('Authorization', authorizationHeader);
    httpRequest.setBody(request);  
    httpResponse = httpObject.send(httpRequest);
    

    【讨论】:

      猜你喜欢
      • 2017-10-13
      • 1970-01-01
      • 2015-08-12
      • 2015-08-07
      • 2019-02-26
      • 2020-11-11
      • 2021-12-20
      • 2018-02-13
      • 1970-01-01
      相关资源
      最近更新 更多