java - 在响应应用程序中返回 200 响应但不返回数据,其中直接在浏览器上点击 url 获得响应
问题描述
我已经配置了 nginx 代理服务器,以便后端服务器和前端服务器现在都在同一个域中,以避免 CORS 错误但无法在我的反应应用程序中获得响应,尽管状态返回 200,我也可以在后端服务器中看到没有错误和当从前端调用 api 但没有得到任何响应但如果我直接从浏览器中点击相同的 api 时,甚至 sql 也会被执行,从而能够获取数据。下面是代码。
安全配置.java
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.csrf().disable()
.authorizeRequests().antMatchers("/signup","/login","/getAuthors","/getPostsByViews","/api/**","/getPosts","/viewPost/**").permitAll().
anyRequest().authenticated().and().
exceptionHandling().and().sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
}
如果我从浏览器中点击相同的 api 就能得到结果
请求标头:
General:
Request URL: http://localhost/api/getPostsByViews
Request Method: GET
Status Code: 200
Remote Address: 127.0.0.1:80
Referrer Policy: no-referrer-when-downgrade
Response Headers:
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Connection: keep-alive
Content-Type: application/json
Date: Sun, 21 Jun 2020 14:03:32 GMT
Expires: 0
Pragma: no-cache
Server: nginx/1.17.7
Transfer-Encoding: chunked
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
Request Headers:
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-IN,en-US;q=0.9,en;q=0.8
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-type: application/json; charset=UTF-8
Cookie: _ga=GA1.1.293989085.1578055123; mp_999298550de6b51ad4a2d300f953b8d5_mixpanel=%7B%22distinct_id%22%3A%20%22app_EMP_MAIN_1%22%2C%22%24device_id%22%3A%20%2216f6b6a3d52578-037bb41e3a8c5a-1d376b5b-fa000-16f6b6a3d538df%22%2C%22%24initial_referrer%22%3A%20%22%24direct%22%2C%22%24initial_referring_domain%22%3A%20%22%24direct%22%2C%22%24user_id%22%3A%20%22app_EMP_MAIN_1%22%2C%22First%20Login%22%3A%20%22FALSE%22%2C%22Platform%22%3A%20%22Web%22%7D; mp_85b4c2f8564a89844a5d5b0511f6c696_mixpanel=%7B%22distinct_id%22%3A%20%22app_EMP_MAIN_1%22%2C%22%24device_id%22%3A%20%2216feaef168263b-001a1921ec9369-39647b0e-fa000-16feaef168390b%22%2C%22%24initial_referrer%22%3A%20%22%24direct%22%2C%22%24initial_referring_domain%22%3A%20%22%24direct%22%2C%22%24user_id%22%3A%20%22app_EMP_MAIN_1%22%2C%22First%20Login%22%3A%20%22FALSE%22%2C%22Platform%22%3A%20%22Web%22%7D; mp_4299603418a0d9f0dc779424045ded30_mixpanel=%7B%22distinct_id%22%3A%20%22Megz_EMP1%22%2C%22%24device_id%22%3A%20%22170193287ed312-06bd1798514f12-1d346652-fa000-170193287ee92d%22%2C%22%24initial_referrer%22%3A%20%22%24direct%22%2C%22%24initial_referring_domain%22%3A%20%22%24direct%22%2C%22%24user_id%22%3A%20%22Megz_EMP1%22%2C%22First%20Login%22%3A%20%22FALSE%22%2C%22Platform%22%3A%20%22Web%22%7D; _ga_J0RTC60E5S=GS1.1.1581501157.13.0.1581501157.0
Host: localhost
Referer: http://localhost/home/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537
来自 React 应用程序的请求标头:
{
method: "GET",
headers: {
'Access-Control-Allow-Origin':"*",
"Content-type": "application/json; charset=UTF-8"
}}
解决方案
推荐阅读
- swift - 在 Firebase 快照中打印具有特定单词的特定子项的所有用户?
- vscode-settings - 如何让 VS Code Bracket Colorizer 随处可用?
- javascript - 删除按钮 Yajra Datatable laravel 7 (http://localhost:8000/articles 405 (Method Not Allowed))
- list - emacs-request 格式化数据返回并隔离数据
- reactjs - React Native StackNavigator 动画方向
- laravel - Laravel - 从axios调用ajax后,控制器内部的sessionId发生变化
- javascript - 如何使用表格中的css“border-collapse:collapse”样式修复边框优先级
- reactjs - 功能组件中的 React.memo 和失效不会失效
- java - 优化没有为 Java SDK 代码激活
- python - 如何在 Python tkinter 中获取入口值?