Problem with Angular 4 HttpClient


#1

This api along with the parameters is working if I use Postman, but as I’m new into Angular 4 and when I try to write the code matching postman configuration it simply doesn’t work. Can you please look at my code and let me know my mistake.
Here’s my code.


#2

What error you are getting?


#3

People are more likely to help if you post text instead of pictures for your code


#4

i get the following error.


#5

Here’s the code.

import {Injectable} from '@angular/core';
import 'rxjs/add/operator/map';
import {HttpClient} from "@angular/common/http";


@Injectable()
export class PdfServiceProvider
{
  private url:string;





  constructor(public http:HttpClient)
  {
  }





  public fetch():void
  {
    this.url = "http://www.anything.com/pdfGenerator/";

    let body:any = {
      orientation: "portrait",
      paperSize  : "letter",
      htmlContent: `<h1>Hello</h1>`,
      return_url : "true",
    };

    this.http.post(this.url, body).
         subscribe(res => console.log(res));
  }
}

#6

As an aside you know you can generate PDF’s locally right?

There’s another is library called pdfmake which is supposed to be even better, not had chance to check it out.

Otherwise I’ll have a play this wknd


#7

I’ve just checked it pdfmake out. Omg it’s WAY better.

Forget whatever you’re doing and do that instead!!! Fully offline, no Cors issues, beautiful structure.


#8

I’ve checked pdfmake & jspdf but both are printing text as a pdf file. I want to make pdf from my html content. How can i pass my html content to pdfMake?


#9

You’d need to change your strategy. Pass what it’s expecting, it’ll yield the most professional looking result.