- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 Android 应用程序中,我尝试通过restTemplate.exchange 发出 GET 请求,但它经常导致 400 错误,很少是 200 响应。
“http://someURL/items/modified/2018-12-20T12%253A47%253A43%252B01%253A00”的 GET 请求结果为 400 ();调用错误处理程序
org.springframework.web.client.HttpClientErrorException:400
我尝试使用编码和解码参数来执行请求,但这是同样的问题。唯一改变的是请求中的时间戳。我不认为这是后端问题,因为我通过 Swagger 和 Postman 在同一界面上发出了几个请求,并且所有请求都工作正常。我也尝试将 spring-android 更新到版本 2.0.0.M3 但仍然是同样的问题。
String url = ServiceAppConstants.HOSTNAME + ServiceAppConstants.REST_ITEMS_MODIFIED + URLEncoder.encode(lastSynchronisationDate);
try {
HttpEntity<String> httpEntity = RestServiceUtils.getHttpEntity(context);
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
// runs in the error here
ResponseEntity<ArrayList> response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, ArrayList.class);
items= response.getBody();
items = mapper.convertValue(items, new TypeReference<List<Items>>(){});
} catch (RestClientException e) {
/* do stuff */
}
设置 token
@NonNull
public static HttpEntity<String> getHttpEntity(Context context) {
UserStorage userStorage = new UserStorage(context);
HttpHeaders headers = new HttpHeaders();
try {
String token = userStorage.getJsonWebToken();
headers.set(ServiceAppConstants.HEADER_SECURITY_TOKEN, token);
}catch (Exception ex){
Log.e(RestServiceUtils.class.getName(), "Could not get json web token", ex);
}
return new HttpEntity<String>("parameters", headers);
}
这就是请求在 android profiler 中的样子
这是通过 swagger 发送请求时的样子
最佳答案
使用新的 HttpEntity( header ); (没有“参数”)
“parameters”字符串是根据 HttpEntity documentation 的请求正文这可能会导致问题。
关于java - restTemplate 交换经常会导致 400 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53882722/
当运行 scala.util.Random().nextInt(3) 81 次时,我看到如下结果(Java 开发人员,请参阅 edit 了解这之间的关系): 200010202002112102222
在使用 native 应用程序在混合模式 C++/CLI 中调试时,我遇到了进程挂起问题。这是无法忍受的,我的调试几乎 70% 都会发生这种情况,我需要一次又一次地重新启动该过程。 是否有任何修补程序
我不知道这是一个错误还是某种误用/错误配置。希望有人能帮忙。谢谢! 如果我更改模块或 list 目录中的文件,通常会导致错误,大部分是以下类型 无法找到节点上的类 在节点上找不到定义类 当 Puppe
我是一名优秀的程序员,十分优秀!