1

how to pass headers in http post request.

import { Http, Response } from '@angular/http';

import { HttpHeaders } from '@angular/common/http';

import { Observable } from 'rxjs';
import { map, catchError } from 'rxjs/operators';

getStreamingURL(): Observable<any> {
		const headers: HttpHeaders = new HttpHeaders({
			'deviceType': 'pc',
			'os': 'web'
		});

		const options = {
			'headers': headers
		};
        return this.http.post(
            environment.apiUrl + '/livetv/apis/v1.0/stream',
            {
				'channelId': 142
			}, options
        ).pipe(map((res) => {
            return res.json();
        }));
    }

1
  • Getting any error? Commented Dec 3, 2018 at 11:51

2 Answers 2

2

a simplified version:

import { Http, Headers, RequestOptions, Response } from '@angular/http';

const headers: HttpHeaders = new HttpHeaders({
            'deviceType': 'pc',
            'os': 'web'
        });

const options = new RequestOptions({ headers: headers });

return this.http.post(urlToPass, options);
Sign up to request clarification or add additional context in comments.

Comments

1

Try this way

import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';

// While call any API.

return new Observable<any>(observer => {
let headers = new HttpHeaders({
    'deviceType': 'pc',
    'os': 'web'
  });
  let options = {
    headers: headers
  }

 this.http.post(URL, param, options)
        .subscribe(data => {
            console.log(data);
         });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.