angular2-http

Angular 2 - http get withCredentials

雨燕双飞 提交于 2019-12-20 05:27:09
问题 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

Custom service in extended Http not getting injected

只谈情不闲聊 提交于 2019-12-18 09:39:37
问题 I want to extend the Http provider to intercept all requests that deliver a 403 status to handle an automatic logout. My custom InterceptingHttp should be declared as Http provider, so I don't need to care about a "special" http provider. I have to following: My custom Http provider import { Injectable } from '@angular/core'; import { Request, XHRBackend, RequestOptions, Response, Http, RequestOptionsArgs } from '@angular/http'; import { Observable } from 'rxjs/Observable'; import {

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

十年热恋 提交于 2019-12-18 08:53:29
问题 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(); })

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

走远了吗. 提交于 2019-12-18 08:52:15
问题 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(); })

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

折月煮酒 提交于 2019-12-18 07:03:31
问题 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),

Getting an object array from an Angular service

 ̄綄美尐妖づ 提交于 2019-12-17 22:33:56
问题 I am new to Angular (and Javascript for that matter). I've written an Angular service which returns an array of users. The data is retrieved from an HTTP call which returns the data in JSON format. When logging the JSON data returned from the HTTP call, I can see that this call is successful and the correct data is returned. I have a component which calls the service to get the users and an HTML page which displays the users. I cannot get the data from the service to the component. I suspect

Angular 2 RxJS Observable: RetryWhen filter retry on error Status

一世执手 提交于 2019-12-17 20:28:02
问题 I am using Angular 2 HTTP library which returns an observable. I want to implement retry on certain error status/code. I have an issue, if the error is not 429, Observable.of(error) is getting executed in error case to retry, but when all your 2 retry fails the execution of flow goes to success block instead of catch block. How to make execution of flow to catch block in all retry fails? return this.http.get(url,options) .retryWhen((errors) => { return errors .mergeMap((error) => (error

How do you POST a FormData object in Angular 2?

戏子无情 提交于 2019-12-17 15:28:32
问题 I need to upload a file and send some json along with it, I have this function: POST_formData(url, data) { var headers = new Headers(), authtoken = localStorage.getItem('authtoken'); if (authtoken) { headers.append("Authorization", 'Token ' + authtoken) } headers.append("Accept", 'application/json'); headers.delete("Content-Type"); var requestoptions = new RequestOptions({ method: RequestMethod.Post, url: this.apiURL + url, headers: headers, body: data }) return this.http.request(new Request

How to correctly set Http Request Header in Angular 2

北城余情 提交于 2019-12-17 05:05:13
问题 I have an Ionic 2 application using Angular 2, which is sending an Http PUT to a ASP.NET Core API server. Here's the method I'm using to send the request: public update(student: Student): Promise<Student> { let headers = new Headers(); headers.append('Content-Type', 'application/json'); headers.append('authentication', `${student.token}`); const url = `${this.studentsUrl}`; return this.http .put(url, JSON.stringify(student), { headers: headers }) .toPromise() .then(() => student) .catch(this

How to use/import http module?

佐手、 提交于 2019-12-17 04:59:18
问题 I've been playing with Angular 2 Quickstart. How can I use/import http module in Angular 2? I've looked at Angular 2 Todo's.js, but it doesn't use the http module. I've added "ngHttp": "angular/http", to dependencies in package.json because I've heard Angular 2 is somewhat modular. 回答1: In version 37 you need to do this: ///<reference path="typings/angular2/http.d.ts"/> import {Http} from "angular2/http"; And run this tsd command: tsd install angular2/http 回答2: Last update: May 11, 2016