如何使用 header、负载和 body 发出 httpclient get 请求? Angular API
How to make a httpclient get request with header, payload and body? Angular API
我需要使用 get 方法、header、负载和 body 调用 API。
请帮助我,如果可能的话,一个例子。
有效负载是否正在发送到 API?然后是 POST 调用,有效负载进入正文。例如:
const payloadUrl = "some_url";
const body = {
payload: "payload";
}
postPayload(): Observable<any> {
return this.http.post<any>(this.payloadUrl, body, httpOptions)
.pipe(
catchError(this.handleError('error', error))
);
}
您可以使用 $q 解析 promise,使用 $http 发送 get 请求 headers。
var deferred = $q.defer();
var req = {
method: 'GET',
url: "some url",
headers:{}
};
$http(req).success(function (res, status, headers, config) {
deferred.resolve(res);
}).error(function (res) {
deferred.reject(res);
});
你可以这样试试
const userData: any = {
example1: example1,
example2: example2,
example3: example3,
};
this.apiCall(userData);
}
apiCall(userData) {
this.http.get<any>('api_link', userData).subscribe(data => {
console.log('response: ', data);
});
}
我需要使用 get 方法、header、负载和 body 调用 API。 请帮助我,如果可能的话,一个例子。
有效负载是否正在发送到 API?然后是 POST 调用,有效负载进入正文。例如:
const payloadUrl = "some_url";
const body = {
payload: "payload";
}
postPayload(): Observable<any> {
return this.http.post<any>(this.payloadUrl, body, httpOptions)
.pipe(
catchError(this.handleError('error', error))
);
}
您可以使用 $q 解析 promise,使用 $http 发送 get 请求 headers。
var deferred = $q.defer();
var req = {
method: 'GET',
url: "some url",
headers:{}
};
$http(req).success(function (res, status, headers, config) {
deferred.resolve(res);
}).error(function (res) {
deferred.reject(res);
});
你可以这样试试
const userData: any = {
example1: example1,
example2: example2,
example3: example3,
};
this.apiCall(userData);
}
apiCall(userData) {
this.http.get<any>('api_link', userData).subscribe(data => {
console.log('response: ', data);
});
}