Java 使用ResponseEntity获取Http响应

Java 使用ResponseEntity获取Http响应,java,spring-boot,Java,Spring Boot,我用创建了一个类,其中包含以下代码行 private String app_key = "XXXXXXXXXXXXXXXXX"; private String app_secret = "XXXXXXXXXXXXXX"; private String appKeySecret = app_key + ":" + app_secret; private byte[] bytes = appKeySecret.getBytes(StandardCharsets.ISO_8859_1); privat

我用创建了一个类,其中包含以下代码行

private String app_key = "XXXXXXXXXXXXXXXXX";
private String app_secret = "XXXXXXXXXXXXXX";
private String appKeySecret = app_key + ":" + app_secret;
private byte[] bytes = appKeySecret.getBytes(StandardCharsets.ISO_8859_1);
private String auth = Base64.encode(bytes);

private OkHttpClient client = new OkHttpClient();

private Request request = new Request.Builder()
        .url("https://sandbox.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials")
        .get()
        .addHeader("authorization", "Basic " + auth)
        .addHeader("cache-control", "no-cache")
        .build();

Response response = client.newCall(request).execute();
我还有一个带有Get映射的控制器,如下所示

  @GetMapping("/auth_token")
public ResponseEntity<MpesaAuth> getToken(@RequestBody Mauth mAuth){
    return new ResponseEntity<>(mpesaAuth, HttpStatus.OK);
}
@GetMapping(“/auth\u令牌”)
公共响应getToken(@RequestBody Mauth Mauth){
返回新的响应状态(mpesaAuth,HttpStatus.OK);
}
但是当我在PostMan上测试端点时,我得到了以下错误

    "timestamp": "2019-09-25T17:26:07.522+0000",
"status": 400,
"error": "Bad Request",
"message": "Required request body is missing: public org.springframework.http.ResponseEntity<com.findfix.payment.config.Mauth> com.findfix.payment.controllers.PaymentController.getToken(com.findfix.payment.config.MpesaAuth)",
"path": "/api/mypayment/v1/auth_token"
}
“时间戳”:“2019-09-25T17:26:07.522+0000”,
“状态”:400,
“错误”:“错误请求”,
“消息”:“缺少必需的请求正文:public org.springframework.http.ResponseEntity com.findfix.payment.controllers.PaymentController.getToken(com.findfix.payment.config.MpesaAuth)”,
“路径”:“/api/mypayment/v1/auth_令牌”
}

我会错过什么呢。提前感谢。

Get
方法将没有正文,因此从
getToken
中删除
@RequestBody-Mauth-Mauth

@GetMapping("/auth_token")
public ResponseEntity<MpesaAuth> getToken(){
    return new ResponseEntity<>(mpesaAuth, HttpStatus.OK);
}

我工作过,但现在我遇到了这个错误。
com.fasterxml.jackson.databind.exc.InvalidDefinitionException:找不到org.springframework.context.annotation.ConfigurationClassEnhance类的序列化程序
我尝试添加
@jsonautodect(fieldVisibility=jsonautodect.Visibility.ANY)
,但没有,这是另一个错误,我不知道你为什么会得到这个@BrianO
@PostMapping("/auth_token") // or @PutMapping
public ResponseEntity<MpesaAuth> getToken(@RequestBody Mauth mAuth){
    return new ResponseEntity<>(mpesaAuth, HttpStatus.OK);
 }