在angular get()中,如何在标头中发送值, [英] in angular get(), how to send a value in header,
本文介绍了在angular get()中,如何在标头中发送值,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Angular代码如下
My Angular code is as follows
getProgramServices(program_id)
{
//environment.dev_url_prefix
console.log(program_id);
let header = new HttpHeaders();
// let headers = new HttpHeaders().append('key', 'value');
// header.append('program_id', program_id);
// header.set('program_id', program_id);
return this.http.get('http://localhost/workers/programServiceList',
{headers: new HttpHeaders().set('program_id', program_id ) }).pipe(map(result => {
console.log(result);
return result;
}));
}
和codeigniter中的rest api如下:
and rest api in codeigniter is as follows:
public function programServiceList_get()
{
header("Access-Control-Allow-Origin: *");
$method = $_SERVER['REQUEST_METHOD'];
if($method != 'GET' && !($this->input->get_request_header('program_id', TRUE))){
json_output(400,array('status' => 400,'message' => 'Bad request! Program ID Not Present'));
}
else {
$resp = $this->Sponsor_api_model->programServiceList();
$response = 200;
json_output($response,$resp);
}
}
每次显示请求错误!程序ID不存在'
Every time it shows 'Bad request! Program ID Not Present'
推荐答案
getProgramServices(program_id) {
const _headers = new HttpHeaders({ 'program_id': program_id}` });
const _url = 'http://localhost/workers/programServiceList';
return this.http.get(_url, {
headers: _headers
});
}
就这么简单.
这篇关于在angular get()中,如何在标头中发送值,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文