angular-httpclient

Why httpclient in angular 4 is assuming that request am sending json data

大憨熊 提交于 2020-01-21 09:07:09
问题 I am using angular 4 http client to a server which returns text data so for that I did something like below this.http.get('assets/a.txt').map((res:Response) => res.text()).subscribe((data: any) => { console.log(data.text()); }); I did not tell it any where that the response is in json format but still it is raising the below error SyntaxError: Unexpected token a in JSON at position 0 at Object.parse () at XMLHttpRequest.onLoad On what basis these people assume as the response is in json

Angular httpClient interceptor error handling

痞子三分冷 提交于 2020-01-21 04:52:05
问题 after reading the documentation on angular about http client error handling, I still don't understand why I don't catch a 401 error from the server with the code below: export class interceptor implements HttpInterceptor { intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { console.log('this log is printed on the console!'); return next.handle(request).do(() => (err: any) => { console.log('this log isn't'); if (err instanceof HttpErrorResponse) { if (err

Calling Http.post does not trigger a post in angular 6

做~自己de王妃 提交于 2020-01-21 02:15:12
问题 I generated my entities components and services according to my model using this tool. Everything worked fine, but I ran into a problem when trying to log a user in my API (that is functional). The http.post() method is not triggered. I'm pretty new to angular and can't figure out what I am doing wrong. Any help would be great! Here's my login method from my UserService (the method is called properly, it's only the http.post() that's not working): /** * Log a user by its credentials. */ login

Nativescript/Angular extending HttpClient

为君一笑 提交于 2020-01-16 09:41:50
问题 I'm since I'm adding nativescript-https to my Nativescript/Angular app I'm making a wrapper. So, since Nativescript's NativeScriptHttpClientModule uses Angular's HttpClientModule I'm extending HttpClient, and I created the http-client.ts file: import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable, from } from 'rxjs'; import * as Https from 'nativescript-https' export interface IRequestOptions { headers?:

Nativescript/Angular extending HttpClient

天大地大妈咪最大 提交于 2020-01-16 09:41:32
问题 I'm since I'm adding nativescript-https to my Nativescript/Angular app I'm making a wrapper. So, since Nativescript's NativeScriptHttpClientModule uses Angular's HttpClientModule I'm extending HttpClient, and I created the http-client.ts file: import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable, from } from 'rxjs'; import * as Https from 'nativescript-https' export interface IRequestOptions { headers?:

Angular : Using the equivalent of RequestOptions of Http with HttpClient

一世执手 提交于 2020-01-15 03:24:10
问题 i'm migrating from Http to HttpClient I'm used to add some headers to my http requests like the following with : import { RequestOptions, Request, RequestMethod, Headers } from '@angular/http'; this.pass = btoa(cuid + ': '); this.pass = "Basic " + this.pass; this.header = new Headers(); this.header.set("Authorization", this.pass); let options = new RequestOptions({ headers: this.header }); return this.http.post(myServiceUrl, {}, options) Now when migrating to httpClient , i ve tried this :

Angular 6 HttpClient return instance of class

末鹿安然 提交于 2020-01-11 04:58:35
问题 Before angular's new HttpClient was introduced, our objects returned from the http api call could be validated with the instanceof keyword. they no longer can with the HttpClient Module. I'm trying some simple methods but the type checks return false every time. the desired behavior of: ``` getCow() { return this.http.get<Cow>(ApiRoute.GET_COW, options) .map(res => res as Cow) .toPromise() .then((c: Cow) => { console.log(c instanceof Cow); //this is false }) } ``` would return true. does

How to make a sequence of http requests in Angular 6 using RxJS

試著忘記壹切 提交于 2020-01-09 11:28:11
问题 I've been looking for a solution all over the web, but couldn't find anything that fits my user case. I'm using the MEAN stack (Angular 6) and I have a registration form. I'm looking for a way to execute multiple HTTP calls to the API and each one is dependent on the returned result from the previous one. I need something that looks like this: firstPOSTCallToAPI('url', data).pipe( result1 => secondPOSTCallToAPI('url', result1) result2 => thirdPOSTCallToAPI('url', result2) result3 =>

How to make a sequence of http requests in Angular 6 using RxJS

£可爱£侵袭症+ 提交于 2020-01-09 11:25:40
问题 I've been looking for a solution all over the web, but couldn't find anything that fits my user case. I'm using the MEAN stack (Angular 6) and I have a registration form. I'm looking for a way to execute multiple HTTP calls to the API and each one is dependent on the returned result from the previous one. I need something that looks like this: firstPOSTCallToAPI('url', data).pipe( result1 => secondPOSTCallToAPI('url', result1) result2 => thirdPOSTCallToAPI('url', result2) result3 =>

Angular HttpClient append headers to HttpHeaders [duplicate]

懵懂的女人 提交于 2020-01-09 10:15:08
问题 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 =