- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在从第三方服务器的 403 http 代码响应获取响应正文时遇到问题。在 2019 年 4 月 5 日之前,我能够正确从第三方获取响应正文,但现在我正在检索一个可能无法从 getResponseBodyAsString 正确转换为字符串的字节。这是 org.springframework.web.client 包的问题吗?
@Autowired
RestClient restClient;
try{
//Request via restTemplate
ResponseEntity<String> responseEntity = restClient.makeClientRequestJson(batch_type.getEndpoint(), HttpMethod.POST, httpHeaders, batch_payload.getRequest(), ProcessorConstants.moduleId);
} catch (HttpClientErrorException | HttpServerErrorException ex) {
loggingService.writeLogs("Error From Third Party Request, Message: " + ex.getMessage() + "| Response Body: " + ex.getResponseBodyAsString(), this.getClass(), LoggingEnum.ERROR, BatchConstants.moduleId);
...
这是 makeClientRequestJson 实现:
public ResponseEntity<String> makeClientRequestJson(String url, HttpMethod httpMethod, HttpHeaders headers, String jsonBody , String moduleId){
RestTemplate restTemplate = new RestTemplate();
HttpEntity<String> entity = new HttpEntity<>(jsonBody, headers);
loggingService.writeLogs("Third Party Request: " + entity.getBody() + "| url: " + url + " | method: " + httpMethod.toString(), RestClientImpl.class, LoggingEnum.INFO, moduleId);
ResponseEntity<String> response = restTemplate.exchange(url, httpMethod, entity, String.class);
loggingService.writeLogs("Third Party Response: " + response.getBody() + "| url: " + url + " | method: " + httpMethod.toString(), RestClientImpl.class, LoggingEnum.INFO, moduleId);
return response;
}
问题是当 ex.getResponseBodyAsString() 返回字节数组时,但我直接从服务器获取 json 响应,如下所示:
{
"code": "403020",
"transactionID": "1555495478-1409322457-83999786",
"message": "Account is Level 1"
}
最佳答案
更新:这是由于客户端服务器的响应 header 造成的,其响应上有一些奇怪的 header ,例如连接 -> 关闭。如果有人遇到此问题,请务必先扫描 header 响应。
关于java - HttpClientErrorException getResponseBodyAsString() 无法将字节解析为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55725428/
我使用 httpResp.sendError(400, "You are missing customer id") 发回响应 当我尝试在客户端检索消息时(使用 Rest 模板调用端点)。 但是,打印
我有一个返回 HttpClientErrorException.NotFound 的第三方服务。当它返回此异常时,我从应用程序中抛出异常,表示输入无效,但对于所有其他异常(例如服务不可用等),我需要使
我正在更新使用 Spring 3.1 Framework 的 RestTemplate 类的 exchange 方法的旧代码。我发现似乎有一个重大的细节遗漏。当我尝试与之通信的其余客户端返回 400
我在从第三方服务器的 403 http 代码响应获取响应正文时遇到问题。在 2019 年 4 月 5 日之前,我能够正确从第三方获取响应正文,但现在我正在检索一个可能无法从 getResponseBo
我正在尝试从“https://swapi.co/api/people/?format=json ”获取数据并使用 RestTemplate.getForObject() 方法将其放入 POJO 中。我
我通过向第 3 方进行 RESTFul 调用(Spring RestTemplate)来处理一些请求。在代码中,我试图处理以下情况。 catch (final Exception ex) {
我尝试将对象发布到 https://api.aftership.com/v4但遇到了以下问题: org.springframework.web.client.HttpClientErrorExcept
我正在尝试通过基本身份验证获取网址。我设置用户/密码如下。同样的凭证也在 postman 中工作。 String RELATIVE_IDENTITY_URL = "http://my_url/api
我正在尝试向身份验证服务器发送帖子消息,并且我正在使用 postforobject。当我运行程序时,我收到“线程“main”中的异常 org.springframework.web.client.Ht
这是关于使用 rest 模板访问 POST api。我收到 org.springframework.web.client.HttpClientErrorException: 400 null。我正在为
当我抛出 HttpClientErrorException 时,根据下面的示例代码,我希望 HTTP 代码为 HTTP 400。相反,我得到一个 HTTP 500 响应代码和消息 400 BAD_RE
我正在从一个模块调用一个服务到另一个模块。但它抛出一个异常: org.springframework.web.client.HttpClientErrorException: 401 null POS
我有网络服务 URL: http://myservice.local/aprovalanduser/?format=json&Name=India 当我使用 resttemplate httpsres
我是 Web 服务的新手。我正在开发一个应用程序,我在客户端使用 AnhularJs1.x 将数据发送到 Spring Rest Controller。 应用程序的架构是基于微服务的。我能够从 ang
我正在与客户端一起设置休息服务器,但几个小时以来我已经遇到了问题。当我调用 getPoints() 方法时,一切正常,但是当我调用 getPoint(Long id)、deletePoint(Long
我使用 spring boot 教程作为基础( https://spring.io/guides/tutorials/spring-boot-oauth2/ ) 测试 Oauth2。 但是,我的身份验
我为 FilterDataController 编写了测试。但是我在执行测试期间出现以下错误。当我手动发送 GET 请求时,我收到了正确的 JSON。 org.springframework.web.
在我的 java 代码中,我尝试使用 RestTemplate 访问微服务,如下所示: headers = new HttpHeaders(); headers.setAccept(A
I am consuming API which has to type of response success response 200 and Bad response 400 both of t
2020年6月12日更新我已经解决了这个问题。问题的原因是我的jetty服务器没有正常启动。我把jdk从14改成了1.7。所有可以吸取的教训是: / 它始终可以接收所有网络请求。 感谢您回答我的问题,
我是一名优秀的程序员,十分优秀!