angular-httpclient

Upgrade Http to HttpClient in Angular 5: “server responded with a status of 415 (Unsupported Media Type)”

心不动则不痛 提交于 2019-12-06 04:55:32
问题 I've upgraded an app from Angular 4.2 to 5 but after changed Http to HttpClient got error on POST request: error the server responded with a status of 415 (Unsupported Media Type) in app.module I've imported HttpClientModule : import { HttpClientModule } from '@angular/common/http'; Old code: post(url: string, model: any): Observable<any> { let body = JSON.stringify(model); let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }

Calling Spring boot api that downloads a pdf from Angular 6 is giving error can't parse response

送分小仙女□ 提交于 2019-12-06 03:39:01
I have a spring boot API that creates a pdf report and download it, if I call the API directly in the browser, the pdf is created and downloaded directly, but when I call that GET API from Angular 6 I get the following error: The Spring boot (java) code: @RequestMapping(value = "/app_report/en", method = RequestMethod.GET) @ResponseBody public void getEnRpt(HttpServletResponse response, @RequestParam("appNum") String appNum) throws JRException, IOException, SQLException { JasperReport jasperReport = JasperCompileManager.compileReport("./src/main/resources/jasperReports/App_created_en.jrxml");

Angular 6 : HttpHeaders Cannot read property 'length' of null in Chrome and IE11 (and not in Firefox)

穿精又带淫゛_ 提交于 2019-12-05 15:31:29
Under my Angular6 app , i'm using HttpClient with some headers injection to my htpp calls to fetch data from my backend server : My service : @Injectable() export class LoadUserInfosService { public _headers = new HttpHeaders().set('Content-Type', 'application/json'); constructor(private httpClient: HttpClient) {} getUserPnsInfos(cuid): Observable<object> { const headers = this._headers.append('login', login); return this.httpClient.get(myBackUrl, {headers: headers}); } } My component where i'm subscribing to it : loadUserInfosFromPns(login) { this.loadUserInfosService.getUserPnsInfos(login)

Display Subscribe Data in Angular 4

六月ゝ 毕业季﹏ 提交于 2019-12-05 04:10:32
问题 I need help in displaying the output of subscribe from an api in Angular 4. How can i do this since I wrote data.data.data but it says property data doesnt exist on type object. How would i output it in the browser? Here's my code below and the api picture below import { Component, OnInit } from '@angular/core'; import { NewsService } from '../news.service'; @Component({ selector: 'app-news-list', templateUrl: './news-list.component.html', styleUrls: ['./news-list.component.css'] }) export

How to exclude some services like login, register from interceptor Angular 5, HttpClient

被刻印的时光 ゝ 提交于 2019-12-05 00:30:17
i wanted to exclude some services using interceptor. app.module.js providers: [ UserService, RolesService, { provide: HTTP_INTERCEPTORS, useClass: TokenInterceptor, multi: true }, ], Login.service.ts return this.httpClient.post(this.appUrl + '/oauth/token', body.toString(), { headers, observe: 'response' }) .map((res: Response) => { const response = res.body; this.storeToken(response); return response; }) .catch((error: any) => { ErrorLogService.logError(error); return Observable.throw(new Error(error.status)); }); } To give this an answer not only in comments as requested ;-) To exclude some

angular httpClientTestingModule httpMock giving error: found 2 requests

谁都会走 提交于 2019-12-04 20:31:28
I have written first test to test service class: service class: import { Injectable } from '@angular/core'; import {HttpClient} from '@angular/common/http' import {IComment} from "../../models/comments"; import {Observable} from "rxjs/observable"; import { mergeMap } from 'rxjs/operators'; @Injectable() export class CommentsDataService { public _url:string = "../../../../assets/json/comments.json"; constructor(private http: HttpClient) { } /** * Return Sample json for * Comment listing. * @returns {json) */ getComments():Observable<IComment> { return this.http.get<IComment>(this._url) } /** *

Multiple Objects into HttpParams

你说的曾经没有我的故事 提交于 2019-12-04 12:42:43
问题 I have some categories in a formcontrol, I send them in an array of string like this: [1,4,6] And that is my actual code: let categoryIds = new Array<String>() this.selectedCategories.forEach((value: string, key: string) => categoryIds.push(key)) let requestOptions = { params: new HttpParams() .set('title', this.createNewForm.controls['title'].value) .append('content', this.createNewForm.controls['content'].value) .append('categoryids', categoryIds.toString()), withCredentials: true } But I

Angular 4 Http POST not working

孤人 提交于 2019-12-04 12:15:35
问题 I hope everyone is doing great. I've recently started working with angular 4.4, i've been trying to post data to my api server, but unfortunately it's not working. I've spent like 2 days on it but still no success. And have already tried 6-7 article even from angular.io. I've tried both Http and Httpclient modules but nothing seems to be working. The problem is, whenever i try to post data to my server, Angular makes http OPTIONS type request instead of POST . this.http.post('http:/

Angular handle for 500 server errors

谁说我不能喝 提交于 2019-12-04 11:44:26
How can I modify my http call to handle(catch) for 500 server errors. I try calling an API but receive a '500 (Internal server error' in the 'err' part of the function. I would like to be able to catch it if possible but am not sure how. Is there a simple way to do this? call_http() { this.http.get<any>('/api/goes/here').subscribe(data => { this.result = data; }, err => { console.log(err); }); } I am not using any headers, map, errorhandler etc. This is just a basic call. If you want to intercept errors when using HttpClient service to make backend calls and don't repeat yourself in every call

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

蓝咒 提交于 2019-12-04 09:47:58
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/123"); expect(req.request.body).toEqual({}); req.flush({}); httpMock.verify(); })); I get of course an