卷曲后在Java中
问题描述:
我试图创建一个Java相当于此:卷曲后在Java中
curl -X POST https://connect.stripe.com/oauth/token \
-d client_secret=sk_test_px1LcMW6VWVSWKrRT4MuHvTY \
-d code=AUTHORIZATION_CODE \
-d grant_type=authorization_code
在Java
按照这里找到DOC:https://stripe.com/docs/connect/oauth#token-request。这是我所到达的,但我一直未经授权。我是否设置了错误?我可以让请求正确地使用curl工作,但不能与java一起工作。
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost("https://connect.stripe.com/oauth/token");
try
{
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("grant_type", "authorization_code"));
nameValuePairs.add(new BasicNameValuePair("code", code));
nameValuePairs.add(new BasicNameValuePair("client_secret", stripeClientId));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null)
{
System.out.println(line);
}
}
catch (IOException e)
{
e.printStackTrace();
}
答
我想通了。看起来我正在用错误的键发出请求。这似乎是发送此请求的正确方法。