angular2-http

Angular 2 - http get withCredentials

此生再无相见时 提交于 2019-12-02 06:53:55
I found something regarding this, but most examples and explanations are deprecated and it's not applicable to RC1. import {Injectable} from "@angular/core"; import {Http, HTTP_PROVIDERS, Response, RequestOptions, URLSearchParams} from "@angular/http"; import 'rxjs/add/operator/map'; @Injectable() export class AuthService { constructor( private _http: Http ) {} GetLoggedUser(){ return this._http.get('http://dev/api/v1/current-user') .map((res:Response) => res.json()) } } I need to make this call exactly as this legacy code: $(document).ready(function() { jQuery.ajax({ type: 'GET', url: 'http:/

Download files with angular2 - ionic 2

纵然是瞬间 提交于 2019-12-01 23:47:06
I have an Ionic 2 app, and I need to download audios from soundcloud. I already have the url that I need to do the request: let url = `https://api.soundcloud.com/tracks/${audio.id}/download?client_id=${this.SC_CLIENT_ID}` I want to know how to do this. I tryed with FileTransfer: public download(audio: any): void { this.platform.ready().then(() => { console.log("Clickeo para descargar: " + audio.id); let url = `https://api.soundcloud.com/tracks/${audio.id}/download?client_id=${this.SC_CLIENT_ID}`; let pathToSaveTo: string = ''; if (this.platform.is('android')) { pathToSaveTo = cordova.file

Download files with angular2 - ionic 2

╄→尐↘猪︶ㄣ 提交于 2019-12-01 21:58:44
问题 I have an Ionic 2 app, and I need to download audios from soundcloud. I already have the url that I need to do the request: let url = `https://api.soundcloud.com/tracks/${audio.id}/download?client_id=${this.SC_CLIENT_ID}` I want to know how to do this. I tryed with FileTransfer: public download(audio: any): void { this.platform.ready().then(() => { console.log("Clickeo para descargar: " + audio.id); let url = `https://api.soundcloud.com/tracks/${audio.id}/download?client_id=${this.SC_CLIENT

angular2/http get location header of 201 response

心不动则不痛 提交于 2019-12-01 20:55:24
问题 I finished successfully the angular2 "tour of heroes" starter tutorial. Then I build an api based on symfony3, FosRestBundle and BazingaHateoasBundle as backend. Now nearly everything works, but on creating new items I'm not able to get the "Location" header from the response to load the newly created Item. Here is my Hero Service: import {Injectable} from "angular2/core"; import {Hero} from "./hero"; import {Http, Headers, RequestOptions, Response} from "angular2/http"; import {Observable}

How to synchronise Angular2 http get?

我是研究僧i 提交于 2019-12-01 02:16:26
I understand using observable I can execute a method when the request is completed, but how can i wait till a http get is completed and return the response using in ng2 http? getAllUser(): Array<UserDTO> { this.value = new Array<UserDTO>(); this.http.get("MY_URL") .map(res => res.json()) .subscribe( data => this.value = data, err => console.log(err), () => console.log("Completed") ); return this.value; } the "value" will is null when its returned because get is async.. You should not try to make http calls behave synchronously. Never a good idea. Coming to your getAllUser implementation it

Angular: How to know if request has been cancelled in HttpClient

∥☆過路亽.° 提交于 2019-11-30 10:06:49
To know if a request has completed, I do if (httpEvent instanceof HttpResponse) . Likewise, how to know if a request is cancelled in HttpInterceptor ? Below is my intercept function. intercept(httpRequest: HttpRequest<any>, httpHandler: HttpHandler): Observable<HttpEvent<any>> { this.requestsPending++; if (this.typeAheads.includes(httpRequest.url.split('/').pop())) this.slimLoadingBarService.start(); else this.flsLoaderService.start(); return httpHandler.handle(httpRequest) .do((httpEvent: HttpEvent<any>) => { if (httpEvent instanceof HttpResponse) { // decrementing counter on each request

Strange behavior when submitting post request in Angular 2

我的未来我决定 提交于 2019-11-30 09:25:17
问题 I realize my title is a bit vague, but here is my situation. I have just started an application in which I am implementing JWT for authentication. I have my server side set up, and can verify it is working as intended. The strangeness is that when you click the button to log in, in Chrome and Firefox it sends the request once, without the body of the request. In Edge it submits it twice, once the way Chrome does, then a second time pretty much immediately afterwards with the body intact. I

Angular: How to know if request has been cancelled in HttpClient

若如初见. 提交于 2019-11-29 15:54:08
问题 To know if a request has completed, I do if (httpEvent instanceof HttpResponse) . Likewise, how to know if a request is cancelled in HttpInterceptor ? Below is my intercept function. intercept(httpRequest: HttpRequest<any>, httpHandler: HttpHandler): Observable<HttpEvent<any>> { this.requestsPending++; if (this.typeAheads.includes(httpRequest.url.split('/').pop())) this.slimLoadingBarService.start(); else this.flsLoaderService.start(); return httpHandler.handle(httpRequest) .do((httpEvent:

How to post json object with Http.post (Angular 2) (php server side)

此生再无相见时 提交于 2019-11-29 14:45:31
I'm trying to recreate Post JSON from angular 2 to php but it doesn't work as there's nothing in the $_REQUEST variable on php side The code: searchHttp({body}: any): Promise<any> { let headers = new Headers ({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers, method: "post" }); let test_this = {"search": "person"}; return this.http.post(this.post_url, JSON.stringify(test_this), options) .toPromise() .then(response => { return response.text(); }) .catch(this.handleError); } Is there something I'm missing? I know that posts works with another format

Can't have a timeout of over 2 minutes with this.http.get?

蹲街弑〆低调 提交于 2019-11-29 12:22:39
My angular 4.3.2 code is calling my back-end service that takes 2-4 minutes to return. Using just the default this.http.get code, I see that the default timeout kicks in after 2 minutes. However when I try to put in a timeout of anything OVER 2 minutes, it fails in that it will never let the timeout be over 2 minutes. I've tried with 100, 100000 (1.7m) and 114000(1.9m) and those work in that it gets timed out right at those values. But when I try 126000 (2.1m), 180000 (3m) and 1800000 (30m), again I see it times out after 2 minutes. this.http.get('myUrl') .timeout(126000) .map((res: Response)