gob*_*obo 1 http angularjs spring-boot ionic-framework
我正在使用服务器端Spring-boot并提供虚拟服务进行测试
我的ServiceCaller.java =
package com.user.server.mfw;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.handler.MappedInterceptor;
@RestController
public class ServiceCaller {
@CrossOrigin(allowedHeaders="*",allowCredentials="true")
@RequestMapping(value="/serviceCaller",method=RequestMethod.POST, headers="content-type=text/*")
@ResponseBody
String serviceListener(@RequestParam("serviceName") String serviceName,HttpSession session,HttpServletRequest theHttpServletReq ) throws IOException
{
if(!serviceName.isEmpty())
{
byte[] encoded = Files.readAllBytes(Paths.get("C://Users//something//Desktop//asd.json"));
return new String(encoded, "UTF-8");
}
return "gelemedi";
}
private void checkActiveSessionControl(HttpSession session)
{
System.out.println("Session Id:" + session.getId() +" // " + session.getCreationTime());
if(session == null)
System.out.println("Null");
else if(session.isNew())
System.out.println("New");
else
System.out.println("Old");
}
}
Run Code Online (Sandbox Code Playgroud)
我的客户端是离子框架,基于angular.js ...
Controller.js
$scope.getInfo = function() {
$http({
url: SERVER_ENDPOINT.url + '/serviceCaller',
method: 'POST',
params: {serviceName: 'deneme'},
withCredentials: true
}).then(function(result) {
var alertPopup = $ionicPopup.alert({
title: 'ALOHA!',
template: 'dksjd ' + result
});
$scope.memberInfo = result.data.accountNumber;
}, function() {
var alertPopup = $ionicPopup.alert({
title: ' failed!',
template: 'da'
});
}
);
};
Run Code Online (Sandbox Code Playgroud)
基本上,当我使用POST方法而不是GET时,我得到"无效的HTTP状态代码403".但是我想用POST来代替GET.但是我无法弄清楚我在哪里弄错了......
任何解决方案将不胜感激!
小智 7
如果您的浏览器正在发送飞行前OPTIONS请求,您所要做的就是通过允许http OPTIONS在您的WebSecurity配置中允许该请求.
.antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5982 次 |
| 最近记录: |