0

我无法在 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 提供用户凭据

4

2 回答 2

0

希望这会帮助你。

这里 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);
于 2014-06-16T10:22:44.320 回答
0

尝试:new UsernamePasswordCredentials("<api-key>", "")

于 2012-06-01T22:46:07.543 回答