400 Bad Request: INVALID_REQUEST, 필수 파라미터 누락

https://docs.tosspayments.com/reference/test/v1/payments/confirm/POST
위 API를 Spring Boot. 400 Bad Request: "{"code":"INVALID_REQUEST","message":"필수 파라미터가 누락되었습니다."}" . .

는 Spring Boot 의 JSON .

        RestTemplate rest = new RestTemplate();

        HttpHeaders headers = new HttpHeaders();

        String testSecretApiKey = tossPaymentConfig.getTestSecretKey() + ":";
        String encodedAuth = new String(Base64.getEncoder().encode(testSecretApiKey.getBytes(StandardCharsets.UTF_8)));

        headers.setBasicAuth(encodedAuth);
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

        JSONObject param = new JSONObject();
        param.put("orderId", orderId);
        param.put("amount", amount);
        param.put("paymentKey", paymentKey);

        //System.out.println(new HttpEntity<>(param, headers));
        return rest.postForEntity(
                PAYMENT_URL + paymentKey,
                new HttpEntity<>(param, headers),
                TossPaymentSuccessDto.class
        ).getBody();

<{"amount":3243,"orderId":"qec1d544-2a34-4f44-ada0-c5213d8fd8da","paymentKey":"e75jWNka9lpP2YxJ4K879ml2Knk5ovVRGZwXLObgyB0vMDm1"},[Authorization:"Basic dGVzdF9za19CYTVQelIwQXJubjlkN3dHRDZ2eHJ2bVluTmVEOg==", Content-Type:"application/json", Accept:"application/json"]>
Was this page helpful?