我试图得到一个消息打印到我的网页控制台时,我点击一个按钮在我的Angular 用户界面。
到目前为止,我已经做了:
我棱角分明的一面:
按钮:
<button id="b1" mat-raised-button color="primary" type="button"(click)=displayString()>Submit</button>
我的.ts文件:
displayString(){
this.httpClient.post('http://localhost:8080/jpmorgan/editquestionSet',{},{ responseType: "text" })
.subscribe(response => console.log(response) );
}
我的Spring Boot面:
springsecurityconfig.java:
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedMethods("HEAD", "GET", "PUT", "POST", "DELETE", "PATCH");
}
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "/**")
.permitAll()
.anyRequest()
.authenticated()
.and()
.httpBasic();
}
@Bean
CorsConfigurationSource corsConfigurationSource() {
UrlBasedCorsConfigurationSource source = new
UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues());
return source;
}
}
控制器
@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/jpmorgan")
public class ApplicationController {
@Autowired
private CompilationService compilationService;
@RequestMapping("/editquestionSet")
public String editquestions() {
return "Questions Added Successfully";
}
}
我在web控制台中遇到错误:
js:3243邮政编码http://localhost:8080/jpmorgan/editquestionset 401 core.js:1449错误httperrorresponse {标题:httpheaders,状态:401,状态文本:“确定”,url:“http://localhost:8080/jpmorgan/editquestionset“,确定:错误, …}
我想要的不是错误,而是来自spring应用程序的响应:
已成功添加问题
1条答案
按热度按时间x4shl7ld1#
以下说明您需要身份验证。
尝试: