angular-httpclient

Angular HttpClient append headers to HttpHeaders [duplicate]

老子叫甜甜 提交于 2020-01-09 10:15:01
问题 This question already has answers here : Adding a HTTP header to the Angular HttpClient doesn't send the header, why? (8 answers) Closed 2 years ago . I am upgrading from the HttpServer to the HttpClientService and as part of that I have to switch my headers from Headers to HttpHeaders. However For some reason my custom headers are no longer being appended. What do I need to update to have the headers appended? private getHeaders(headers?: HttpHeaders): HttpHeaders { if (!headers) { headers =

Angular 5 Jasmine Error: Expected one matching request for criteria found none

淺唱寂寞╮ 提交于 2020-01-01 09:48:53
问题 I have a very simple service call and a jasmine test for it. Service call: myServiceCall(testId: number) : void { const url = `${this.url}/paramX/${testId}`; this.http.put(url, {},{headers: this.headers}).subscribe(); } My Test Method: it('should call myServiceCall', inject([MyService], (service: MyService) => { let testId = undefined; service.myServiceCall(testId); let req = httpMock.expectOne(environment.baseUrl + "/paramX/123"); expect(req.request.url).toBe(environment.baseUrl + "/paramX

Angular 5 Jasmine Error: Expected one matching request for criteria found none

六月ゝ 毕业季﹏ 提交于 2020-01-01 09:48:28
问题 I have a very simple service call and a jasmine test for it. Service call: myServiceCall(testId: number) : void { const url = `${this.url}/paramX/${testId}`; this.http.put(url, {},{headers: this.headers}).subscribe(); } My Test Method: it('should call myServiceCall', inject([MyService], (service: MyService) => { let testId = undefined; service.myServiceCall(testId); let req = httpMock.expectOne(environment.baseUrl + "/paramX/123"); expect(req.request.url).toBe(environment.baseUrl + "/paramX

How to handle unauthorized requests(status with 401 or 403) with new httpClient in angular 4.3

血红的双手。 提交于 2019-12-31 15:51:56
问题 I have an auth-interceptor.service.ts to handle the requests import {Injectable} from '@angular/core'; import {HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http'; import {Observable} from 'rxjs/Observable'; import {Cookie} from './cookie.service'; import {Router} from '@angular/router'; @Injectable() export class AuthInterceptor implements HttpInterceptor { constructor(private router: Router) {} intercept(req: HttpRequest<any>, next:

405 Method Not Allowed despite CORS

妖精的绣舞 提交于 2019-12-31 02:26:42
问题 I am trying to develop a frontend application using Angular. Since I added the authorization header to the HTTP POST and GET requests, I'm getting 405 Method Not Allowed , although I seemingly allow everything on the server side. The debugger in my browser Chrome says it's asking for Access-Control-Request-Method: POST and Access-Control-Request-Headers: authorization , my backend allows both, access-control-allow-methods: GET, POST and access-control-allow-headers: authorization , as well as

405 Method Not Allowed despite CORS

三世轮回 提交于 2019-12-31 02:26:05
问题 I am trying to develop a frontend application using Angular. Since I added the authorization header to the HTTP POST and GET requests, I'm getting 405 Method Not Allowed , although I seemingly allow everything on the server side. The debugger in my browser Chrome says it's asking for Access-Control-Request-Method: POST and Access-Control-Request-Headers: authorization , my backend allows both, access-control-allow-methods: GET, POST and access-control-allow-headers: authorization , as well as

How to send a boolean from a http request to a component?(Angular)

梦想的初衷 提交于 2019-12-24 23:16:06
问题 I created a program with Angular 7 and i want to catch the http request in a boolean and to transfer it to a component. I tried to use BehaviourSubject with next for this. So the boolean has to be true inside these two functions checkin() and checkOut(). I attached the code. I would appreciate any help. Thanks! import { Component, OnInit } from '@angular/core'; import { HttpLoadingInterceptor } from '../../../interceptor/http-loading.interceptor'; import { Subscription } from 'rxjs';

ionic 3 HttpClient get status + send headers

我与影子孤独终老i 提交于 2019-12-24 21:58:55
问题 i'm using the HttpClientModule on ionic 3, and i want to do a get on my api let email = "test@email.com"; let password = "password"; let headers = new HttpHeaders(); this.http.get('http://127.0.0.1:8000/api/login',{ headers: {'email':email,'password':password} }); i don't want to get the json but only the status of the request, for doing something like : if(status == 200) { ... } esle { ... } can you guys please help me ? Thank you 回答1: Add observe : 'response' in header options of http.get

Angular5 HttpClient send data but server can not understand its params

感情迁移 提交于 2019-12-24 21:25:32
问题 When I submit a regular HTML form, My back-end service ( written in Laravel ) can understand POST parameters. I checked the request header in the browser. Request parameters are: Form Data: _token:v4xCN9fHMpZhoQMGHfbqI01XDsQ1nCxYhy3RDrw5 username:root password:123456 Then I wrote the following method to send a post request to the server via angular5 HttpClient : public post(url: string, data: any): Observable<any[]> { const headers = new HttpHeaders({ 'Content-Type': 'application/x-www-form

Angular5 Authentication to Api with jwt

我只是一个虾纸丫 提交于 2019-12-24 19:43:25
问题 I have an api accessible through an jwt token. I have the expected result with postman and curl ( curl -X POST http://localhost/api/login_check -d _username=login -d _password=pass ) but not with angular. Successful header request with postman: POST /api/login_check cache-control: no-cache postman-token: 2b4a6be8-5c3d-4c66-99f9-daa49572d4bf user-agent: PostmanRuntime/7.1.1 accept: */* host: localhost cookie: PHPSESSID=06u39ri0rr2i2sgdkjr451d6tj accept-encoding: gzip, deflate content-type: