2012-05-30 63 views
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); 



    } 


} 

我提出我的代碼......在這裏我HV使用HTTP基本認證,以提供用戶憑據stripe.com

+0

什麼,當你嘗試會發生什麼? – Ashe

+0

它表示沒有找到默認憑證。並且驗證失敗 – behinddwalls

+0

爲什麼不使用條帶Java綁定? https://stripe.com/docs/libraries – brian

回答

0

嘗試:new UsernamePasswordCredentials("<api-key>", "")

+0

dis不起作用 – behinddwalls

+0

如果它不起作用,您爲什麼接受答案? – Madbreaks

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);