0

I have an App in which I make requests like the one you see in the following code:

import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class ResourcesApiProvider {
  public direccion = my_url_app;

  constructor(public http: Http) {
  }

  getCars(car_id) {
    let repos = this.http.get(this.direccion + 'api/cars.json' + '?car_id=');

    return repos;
  }
}

The API I have responds both via HTTP and HTTPS for now, but I want to change all the communication to HTTPS, so I was wondering... what I can do so that Angular / Ionic the app sends encrypted requests to the API?, is it enough to just use the HTTPS URL of my API when I do the assignment public direccion = my_url_app?

I'm asking because some answers from here say that I have to add / at the end, but I'm not sure if that's still the case, etc.

Greetings.

Freego
  • 456
  • 7
  • 18
Patricio Sard
  • 2,092
  • 3
  • 22
  • 52

1 Answers1

0
import { Injectable } from '@angular/core';

import { Model } from './Model.model';

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

import { Observable } from 'rxjs/Rx';

import { LoginService } from '../../core/auth/login/login.service';

import { environment } from '../../../environments/environment';

@Injectable()

export class Service {

    requestOptions: RequestOptions;

    constructor(private http: Http, loginService: LoginService){
        const headers = new Headers({'Authorization': loginService.getToken()});
        this.requestOptions = new RequestOptions({headers : headers});
    }

    getEventsType(): Observable<any[]> {
        return this.http.get(`${environment.apiUrl}/events`, this.requestOptions)
            .map( mapAny );
    }

}

function mapAny(response:Response): any[] {

    // The response of the API has a results
    // property with the actual results

    return response.json().data;

}

You must to change it

enter image description here

Albert Einstein
  • 7,472
  • 8
  • 36
  • 71
  • 2
    Please refer this help page [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) – v8-E Oct 01 '18 at 03:51