'Why one request triggered CORS policy but the other not?
I use the same request func to yield call
two api on the server.
Model func code:
const pomdata = yield call(pullInfo1, payload)
const data = yield call(pullinfo2, payload)
And server code is :
@RestController
@RequestMapping(value = "/intf")
public class IntfController {
@Transactional
@RequestMapping(path ="/pullinfo1", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, Object> pullinfo1(HttpServletRequest request) throws Exception {
try{
xxxxx
return successMap //This one return the right reponse
} catch {
return FailMap;
}
}
@Transactional
@RequestMapping(path ="/pullinfo2", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, Object> pullinfo2(HttpServletRequest request) throws Exception {
try{
xxxxx
return successMap //This one return the wrong reponse which Triggered CORS policy
} catch {
return FailMap;
}
}
one api give the right reponse but the other triggered the CORS policy. They are all running on the same mcrsverice and under the same @RequestMapping
route.
The Server CORS Filter get the origin and typed on the console.
CORSFilter get the origin image
And according to the code:
String origin = request.getHeader("origin");
String origin = request.getHeader("origin");
logger.info("#### req origin ####" + origin);
HttpServletResponse response = (HttpServletResponse) res;
if (origin != null) {
response.setHeader("Access-Control-Allow-Origin", origin);
}
The response shall have the Access-Control-Allow-Origin,But it doesn't.
Here is the right reponse like pullinfo1
:
right reponse and Header
Here is the wrong reponse like pullinfo2
:
wrong response and Header
By the way,they all have same request header except request url.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|