RestTemplate.exchange返回带有ReadOnlyHttpHeaders的ResponseEntity。我想添加/修改这些标题,但是由于它是只读的,我该怎么做?
答案 0 :(得分:6)
如果上述答案对您不起作用,请尝试以下
HttpHeaders httpHeaders = HttpHeaders.writableHttpHeaders(httpEntity.getHeaders());
答案 1 :(得分:1)
HttpHeaders实现MultiValueMap,您可以创建一个新的可变HttpHeaders
,其中包括ReadOnlyHttpHeaders
并进行以下修改:
HttpHeaders readOnlyHttpHeaders = ...
HttpHeaders mutableHttpHeaders = new HttpHeaders(readOnlyHttpHeaders);
mutableHttpHeaders.put("foo", List.of("bar"));
答案 2 :(得分:0)
for(i=0;i<point.Count;i++){
x1 += point[i].X1;
x2 += point[i].X2;
}
meanx1 = x1 / point.Count;
meanx2 = x2 / point.Count;
for(i=0;i<point.Count;i++){
totalX1 += Math.Pow(point[i].X1 - meanx1, 2);
totalX2 += Math.Pow(point[i].X2 - meanx2, 2);
}
normX1 = totalX1 / (point.Count - 1);
normX2 = totalX2 / (point.Count - 1);
normX1 = normX1 / 100;
normX2 = normX2 / 100;
并且mutatedExchange将具有带有新键:值对的标头。