我正在尝试转换 Unirest
HttpResponse<String> response = Unirest.post("https://api.tap.company/v2/charges")
.header("authorization", "Bearer sk_test_XKokBfNWv6FIYuTMg5sLPjhJ")
.header("content-type", "application/json")
.body("{\"amount\":1,\"currency\":\"KWD\",\"receipt\":{\"email\":false,\"sms\":true},\"customer\":{\"first_name\":\"test\",\"phone\":{\"country_code\":\"965\",\"number\":\"50000000\"}},\"source\":{\"id\":\"src_kw.knet\"},\"redirect\":{\"url\":\"http://your_website.com/redirect_url\"}}")
.asString();
到凌空
RequestQueue queue = Volley.newRequestQueue(this);
String url = "https://api.tap.company/v2/charges";
StringRequest TapREQUEST = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override public void onResponse(String response) {
Log.w("OnResponse:", response);
}
}, new Response.ErrorListener() {
@Override public void onErrorResponse(VolleyError error) { error.printStackTrace(); }
}) {
@Override public Map<String, String> getHeaders() {
Map<String,String> headers = new HashMap<>();
headers.put("content-type", "application/json");
headers.put("authorization", "Bearer sk_test_XKokBfNWv6FIYuTMg5sLPjhJ");
//String auth = "Bearer " + Base64.encodeToString("sk_test_XKokBfNWv6FIYuTMg5sLPjhJ".getBytes(), Base64.DEFAULT);
//headers.put("authorization", auth);
return headers;
}
};
queue.add(TapREQUEST);
但是我得到E /Volley:[396]BasicNetwork.performRequest:意外响应代码400用于 https://api.tap.company/v2/charges
当我点击链接时,我得到
{“errors”:[{“code”:“2107”,“description”:“Authorization Required”}]}
慕容森
相关分类