angularjs – 如何向每个Angular.js $http请求添加添加请求参数(
发布时间:2020-12-17 17:58:14 所属栏目:安全 来源:网络整理
导读:我的混合应用程序基于AngularJS并使用php REST api. 我想直接从我的Angular应用程序调试php api,而不是使用REST控制台或Postman.这将节省大量时间,特别是对于POST和PUT请求. 为此,我需要为每个请求添加一个参数,如下所示: http://localhost:8000/api/contac
|
我的混合应用程序基于AngularJS并使用php REST api.
我想直接从我的Angular应用程序调试php api,而不是使用REST控制台或Postman.这将节省大量时间,特别是对于POST和PUT请求. 为此,我需要为每个请求添加一个参数,如下所示: http://localhost:8000/api/contacts?XDEBUG_SESSION_START=PHPSTORM 我可以配置$http这样做吗? 解决方法
您可以使用httpInterceptor(官方$http
documentation包含更多信息)
// register the interceptor as a service
$provide.factory('xdebugInterceptor',function($q) {
return {
// optional method
'request': function(config) {
// do something on success
// !!! adjust the config object
// add request param XDEBUG_SESSION_START=PHPSTORM
// it will be added to every made request
config.params = config.params || {};
config.params.XDEBUG_SESSION_START: "PHPSTORM";
return config;
},// optional method
'requestError': function(rejection) {
// do something on error
return $q.reject(rejection);
},// optional method
'response': function(response) {
// do something on success
return response;
},// optional method
'responseError': function(rejection) {
// do something on error
return $q.reject(rejection);
}
};
});
// make this conditional so you use it only in DEV mode
$httpProvider.interceptors.push('xdebugInterceptor');
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- WebService(三)—JDK内置JAX-RS实现Rest WebSe
- 外壳 – 编译模式下的ANSI着色
- angular – 如何为datepicker实现MD_DATE_FORMAT
- Kubelet bootstrap认证配置步骤
- angularjs – Angular选择中的默认文本
- Scala:Cats,OptionT [Future,T]和ApplicativeEr
- angular 去掉ng-repeat自动添加的$$hashkey
- WebService大讲堂之Axis2(1):用POJO实现0配置
- npm – bootstrap@4.0.0-alpha.3无效
- unix:如何连接grep中匹配的文件
热点阅读
