我有这个代码:
app.controller('MainCtrl', function ($scope, $http){
$http.get('api/url-api')
.success(function (data, status, headers, config){
}
}
Run Code Online (Sandbox Code Playgroud)
在我当地的环境中,工作正常,但在服务器中,返回此错误:
TypeError:$ http.get(...).success不是函数
有任何想法吗?谢谢
我正在触发HTTP请求,我从中得到了有效的回复.响应还有一个我希望阅读的标题X-Token.我正在尝试下面的代码来读取标题,但是,我得到null作为结果
this.currentlyExecuting.request = this.http.request(reqParams.type, reqParams.url, {
body: reqParams.body,
responseType: 'json',
observe: 'response'
}).subscribe(
(_response: any) => {
// Also tried _response.headers.init();
const header = _response.headers.get('X-Token');
console.log(header);
onComplete(_response.body);
},
_error => {
onComplete({
code: -1,
message: Constants.WEBSERVICE_INTERNET_NOT_CONNNECTED
});
}
);
Run Code Online (Sandbox Code Playgroud)
X-Token在Chrome检查中检查时,响应显示标题存在.尝试在StackOverflow上查看几个相关问题,但没有任何帮助.
我有类似于以下代码domain.com:
$http.post("http://api.domain.com/Controller/Method",
JSON.stringify(data),
{
headers: {
'Content-Type': 'application/json'
}
})
.then(function (response) {
console.log(response);
}, function (response) {
// something went wrong
});
}
Run Code Online (Sandbox Code Playgroud)
它与我的.NET API很好地通信.response.data拥有我的服务器需要给我的所有数据.但是我们有一个新的安全令牌,我们从API传递给客户端,我们将它传递回数据包头中的客户端.我知道令牌正在传回,因为我可以在chrome调试器的网络选项卡上的数据包中读取它.但是response.headers()只包含content-type:"application/json; charset=utf-8"它没有包中的内容.有谁有想法?
这样的数据从API返回(C#)
HttpContext.Current.Response.AppendHeader("session",Guid.NewGuid().ToString());
所以我希望response有一个标题session,但它没有.然而它在数据包中.
您知道我如何从get请求访问响应标头吗?
我有一个返回承诺的服务功能。我的控制器解析了Promise,然后在.then函数中,我需要响应头中的内容类型。
我尝试使用console.log(headers())显示的“ headers”参数,但控制台中显示的错误“ headers()不是函数”。
我的服务:
.factory('GetResultFile',
['$http', '$q',
function ($http, $q) {
var service = {};
service.getResult = function(id, rid) {
var deferred = $q.defer();
$http
.get('http://localhost:9999/v1/jmeter/' + id + '/results/' + rid, {cache: false})
.then(function(data, status, headers, config) {
if(data.status == 200) {
console.log(data.status);
deferred.resolve(data);
}
else {
deferred.reject(data);
}
});
return deferred.promise;
}
return service;
Run Code Online (Sandbox Code Playgroud)
}]);
控制器:
$scope.getResult = function(rid) {
console.log($scope.id);
GetResultFile.getResult($scope.id, rid)
.then(function(data, headers) {
//console.log(headers.Content-type);
console.log(headers());
console.log(data);
console.log("Download succeed");
console.log(data.status);
var file = new …Run Code Online (Sandbox Code Playgroud) angularjs ×3
javascript ×2
ajax ×1
angular ×1
angular5 ×1
c# ×1
function ×1
header ×1
http ×1
http-headers ×1
typescript ×1