我目前正在开发使用网站AngularJS,应用程序是为了POST与GET数据和从已经运行的MVC4应用.此MVC4应用程序正在使用Windows身份验证.
我可以通过浏览器直接访问MVC4应用程序并导航返回JSON的URL .现在,我只是手动下载了这个JSON并用它构建了应用程序.
当我直接从我的AngularJS应用程序请求服务器时,我的问题出现了.我试图使用基本身份验证在另一台服务器上工作,这很好.但现在我需要使用NTLM身份验证来使用Windows身份验证.
我研究了构建Type 1消息并在授权标题中设置它,但我很快就被淹没了.
我觉得服务器和客户端之间需要大量的通信,只是为了进行身份验证,使得使用AngularJS和Windows身份验证(NTLM身份验证)没有吸引力?我该如何解决这个问题?
asp.net asp.net-mvc windows-authentication angularjs angularjs-http
我有一个AngularJs前端和一个NodeJS后端.我正在尝试基于AngularJS中的一些参数在NodeJS上构建PDF并返回PDF作为响应.
当我从AngularJS发出GET请求时,我正在使用的代码似乎正常工作,但是当我发出POST请求时它返回一个空白的PDF.我需要发出POST请求,因为我必须发送一些特定的数据.
我首先将文件保存在磁盘上,然后将其发送到前端,以便我可以看到正确生成PDF.它未正确发送或在FrontEnd上正确读取.
以下是我的AngularJS代码
var url = {{My Node Server URL}};
(Note: Works when I make a Get request, without sending post params)
var $promise = $http.post(encodeURI(url), {
responseType: 'arraybuffer',
competitors: competitors,
channels: channels
});
$promise.then(
function success(response) {
var blob = new Blob([response.data], { type : 'application/pdf' });
var pdfLink = (window.URL || window.webkitURL).createObjectURL( blob );
window.open(
pdfLink,
'_blank' // <- This is what makes it open in a new window.
);
cb(pdfLink);
}, function error(response) {
--Error Handling-- …Run Code Online (Sandbox Code Playgroud) 我很难理解这个错误...我不太明白为什么它不是一个函数....
angular.module('mkApp').factory('mkService', function ($http, $log) {
function getLookUp(successcb) {
$http = ({
method: 'GET',
url: 'api/Entries/'
}).success(function (data, status, header, config) {
successcb(data);
}).
error(function (data, status, header, config) {
$log, warn(data, status, header, config);
});
};
return {
lookUp: getLookUp
}
});
angular.module('mkApp').controller('mkControler', function ($scope, mkService) {
mkService.lookUp(function (data) {
$scope.ddl = data;
console.log(ddl);
});
});
Run Code Online (Sandbox Code Playgroud)
这是我的HTML
<div ng-app="mkApp">
<div ng-controller="mkControler">
<table>
<tr>
<td> First Name</td>
<td> Last Name</td>
</tr>
<tr>
<td><input type="text" /></td>
<td><input type="text" /></td>
</tr>
<tr> …Run Code Online (Sandbox Code Playgroud) javascript angularjs angularjs-scope angularjs-controller angularjs-http
问题陈述:我的UI应用程序在9000端口(grunt项目)上运行,我的服务器端spring引导项目在8421端口上运行.除登录和注销外,我能够从我的UI应用程序中点击所有URL.请告诉我如何使用CORS配置spring security登录和注销.
App.js
$scope.login = function() {
$http.post('http://localhost:8421/login', $.param($scope.credentials), {
headers : {
'content-type' : 'application/x-www-form-urlencoded'
}
}).success(function() {
console.log('login success');
});
}).error(function() {
console.log('login error');
});
};
Run Code Online (Sandbox Code Playgroud)
SecurityConfiguration.java
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.addFilterBefore(new SimpleCORSFilter(), ChannelProcessingFilter.class)
.authorizeRequests().antMatchers("/rest/**").permitAll()
.and().logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/index.html")
.and().exceptionHandling().authenticationEntryPoint(authenticationEntryPoint)
.and().formLogin().successHandler(authenticationSuccessHandler)
.and().formLogin().failureHandler(authenticationFailureHandler)
.and().csrf().disable();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder());
}
}
Run Code Online (Sandbox Code Playgroud)
SimpleCORSFilter.java
public class SimpleCORSFilter implements Filter {
@Override
public void doFilter(ServletRequest req, ServletResponse …Run Code Online (Sandbox Code Playgroud) 我想在 $ resource构造url 之前以编程方式更改路由参数.我无法使用angular的http拦截器来执行此操作,因为此时路由已经连接在一起.
给出一个Assortment.model.js
module.exports = function($resource) {
return $resource("", {}, {
get: {
url: "/assortment/:model/:id",
method: "GET",
params: {id: "@id", model: "@model"} //< this needs to be uppercase
}
});
};
Run Code Online (Sandbox Code Playgroud)
......和一些controller.js
["Supplier", function(Supplier) {
Supplier.Assortment.get({ id: 5, model: "user" })
}]
Run Code Online (Sandbox Code Playgroud)
如何强制执行始终转换{model: "user"}为的挂钩{model: "User"}
javascript angularjs angularjs-resource ngresource angularjs-http
我仍然无法理解使用 $q 服务的作用,(它究竟会添加什么)如果你想创建一个只需要通过 http 调用一个 API 的服务,在这种情况下我不知道为什么应该'我只是执行以下操作(不使用 $q):
this.getMovie = function(movie) {
return $http.get('/api/v1/movies/' + movie)
.then(
function(response) {
return {
title: response.data.title,
cost: response.data.price
});
},
function(httpError) {
// translate the error
throw httpError.status + " : " +
httpError.data;
});
};
Run Code Online (Sandbox Code Playgroud) node.js服务器给出"这是一个字符串".(writeHeader,write(string),end).
执行$ http请求时,我看到node.js服务器正在响应并发回信息.
在Angular中,我执行以下请求:
angular.module('phoneList').
component('phoneList', {
templateUrl: 'phone-list/phone-list.template.html',
controller: function PhoneListController($http) {
var self = this;
$http.get('http://127.0.0.1:8081/echo').then(function(response) {
self.data = response.data;
}, function(err) {
self.error = err;
self.status = response.status;
self.statusText = response.statusText;
});
}
});
Run Code Online (Sandbox Code Playgroud)
响应
{"data":null,"status": - 1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":" http: //127.0.0.1:8081/echo ","headers":{"接受":"application/json,text/plain,/ "}},"statusText":""}
我试过从node.js或HTML-text发送JSON.没有不同.
我将替换$http为Fetch API,然后将其替换$q为Promise API。因此,Angular不再运行摘要循环,因此UI无法呈现。为了解决这个问题,我尝试了Zone.js,这似乎可以部分解决我们的问题。不幸的是,其API在0.6中已完全更改,因此我们使用的是旧版0.5.15。
现在到实际问题了。
刷新页面时,Angular会按预期进行配置和引导应用程序。在这个阶段,我初始化区和装饰$rootScope.apply用区和$rootScope.$digest()。现在,当我在状态/路由(使用ui-router)之间进行转换时,一切都按预期工作,但是当完全刷新时,就会出现竞争状况,并且区域/摘要无法正确运行。我不确定如何解决。
我在angular.run()块中包含以下代码:
console.log('Zone setup begin');
const scopePrototype = $rootScope.constructor.prototype;
const originalApply = scopePrototype.$apply;
const zoneOptions = {
afterTask: function afterTask() {
try {
$rootScope.$digest();
} catch (e) {
$exceptionHandler(e);
throw e;
}
}
};
scopePrototype.$apply = function $applyFn() : void {
const scope = this;
const applyArgs = arguments;
window.zone.fork(zoneOptions).run(() => {
originalApply.apply(scope, applyArgs);
console.log('Zone + $digest run!');
});
};
console.log('Zone setup end');
Run Code Online (Sandbox Code Playgroud)
在上方可以看到我在区域初始化开始,结束和运行时(+ …
javascript angularjs angularjs-http angular-promise fetch-api
首先,我不擅长angularjs.
虽然我一直在研究$ q,但我遇到了一个奇怪的问题.
当我使用$ q.all时,我将$ http放在常规序列中,期望得到相同顺序的结果,
但我得到的是随机结果.
看到这个并纠正我的愚蠢.
$q.all([
HttpService.editItem(
$scope.$parent.category_id, // category id
Define.CAR_CAT, // category url to request
$scope.car_id, // car_id wanna edit
{car_name: inputValue.toUpperCase()} // data
),
HttpService.getCarList(
$scope.$parent.category_id, // category id
Define.CAR_CAT // category url to request
)
]).then(function (results) {
if (results[0].statusText === 'OK' && results[1].statusText === 'OK') {
.....
});
Run Code Online (Sandbox Code Playgroud)
'HttpService'是我的应用程序的服务.它会回报承诺.
我的期望是什么
首先编辑汽车名称,稍后获取汽车清单.
但我得到的结果是先获得车名,然后再编辑车名.
我正在使用
return $ q(function(resolve,reject){});
而不是使用
$ q.defer();
.
.
.
.
这些是我的HttpService部分
function editItem(cat_id, cat_url, content_id, item_data) {
return $q(function …Run Code Online (Sandbox Code Playgroud) Angular 1.6.3不允许允许的请求,1.5.8我收到此错误:
$sce:insecurl
Processing of a Resource from Untrusted Source Blocked
Run Code Online (Sandbox Code Playgroud)
完整错误可在此处获得.
我想升级我的角度版本1.6.3以获得最新和最好的,但我依赖于这个API.有没有办法让我将其标记为可信API或使用此API的其他方式?这两个版本之间的区别是什么?
这是我试图运行的代码:
var app = angular.module('app', []);
app.controller('firstController', ['$http', function($http) {
console.log('firstController up and running');
var key = 'XXXXXXXXXXXXX'; // is an actual key
var self = this;
self.animal = {};
self.getRandomPet = function(){
var query = 'http://api.petfinder.com/'; // baseURL for API
query += 'pet.getRandom'; // selecting the method we would like to return
query += '?key=' + key; // Giving …Run Code Online (Sandbox Code Playgroud) angularjs ×10
angularjs-http ×10
javascript ×4
angularjs-q ×1
asp.net ×1
asp.net-mvc ×1
cors ×1
express ×1
fetch-api ×1
jsonp ×1
ngresource ×1
node.js ×1
spring-rest ×1
wkhtmltopdf ×1