【发布时间】:2026-01-14 06:15:01
【问题描述】:
我正在尝试发送如下帖子:
curl -X POST https://app.referralsaasquatch.com/api/v1/{tenant_alias}/rewards/account/{accountId}/user/{userId} \
-u :API_KEY \
-H "Content-Type: application/json" \
-d '{
"type": "CREDIT",
"cancellable": true,
"unit": 'credit-in-cents',
"assignedCredit": 150*100,
"currency": EUR
}'
- API_KEY:API_KEY_VALUE
- TENANT_ALIAS:test_ai38kl5mysg8n
-
授权:基本 Base64.encode(API_KEY)
public static void executePost() { // TODO code application logic here String STRURL = "https://app.referralsaasquatch.com/api/v1/" + "test_ai38kl5mysg8n" + "/rewards/account/" + ActionGetRsqInfo.IDINTIFIRE + "/user/" + ActionGetRsqInfo.IDINTIFIRE; System.out.println(STRURL); URL url; HttpURLConnection urlConn = null; StringBuilder sb = new StringBuilder(); try { DataOutputStream printout; url = new URL(STRURL); urlConn = (HttpURLConnection) url.openConnection(); urlConn.setDoInput(true); urlConn.setDoOutput(true); urlConn.setUseCaches(false); urlConn.setRequestMethod("POST"); urlConn.setRequestProperty("Content-Type", "application/json"); urlConn.setRequestProperty("API_KEY", "API_KEY_VALUE"); urlConn.connect(); JSONObject json = new JSONObject(); json.put("assignedCredit","1500"); json.put("cancellable", "true"); json.put("name", "Dollar Credit"); json.put("type", "CREDIT"); json.put("unit", "CENTS"); // Send POST output. printout = new DataOutputStream(urlConn.getOutputStream()); printout.writeBytes(URLEncoder.encode(json.toString(), "UTF-8")); printout.flush(); printout.close(); int HttpResult = ((HttpURLConnection) urlConn).getResponseCode(); if (HttpResult == HttpURLConnection.HTTP_OK) { BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream(), "utf-8")); String line = null; while ((line = br.readLine()) != null) { sb.append(line + "\n"); } br.close(); System.out.println( sb.toString()); } else { System.out.println("bad URL " + ((HttpURLConnection) urlConn).getResponseMessage()); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (urlConn != null) urlConn.disconnect(); } }
【问题讨论】:
-
请向我们提供您遇到的错误?