alvarcarto / url-to-pdf-api

Web page PDF/PNG rendering done right. Self-hosted service for rendering receipts, invoices, or any content.
MIT License
7.03k stars 779 forks source link

URL and HTML issues with POST #68

Closed emilehay closed 6 years ago

emilehay commented 6 years ago

Hi there,

I'm having trouble getting a POST request in Mithril.js to a locally hosted version of this repo to generate a PDF from the URL I pass through. The URL field is undefined on the server side.

This is what my call looks like:

m.request({
        method: "POST",
        url: "http://localhost:9000/api/render",
        headers: {
            "content-type": "application/json",
        },
        data: {
            "url": "http://www.google.com",
        },
    })
    .then(function (result) {
        try{
            console.log('Worked');
        } catch (error) {
            console.log('Error:' + error);
        }
    })
    .catch(function (result) {
        console.log('Error: ' + result);
    })

On the server side I output the opts. I get this:

{ cookies: [],
  scrollPage: false,
  emulateScreenMedia: true,
  ignoreHttpsErrors: false,
  html: {},
  viewport:
   { width: 1600,
     height: 1200,
     deviceScaleFactor: undefined,
     isMobile: undefined,
     hasTouch: undefined,
     isLandscape: undefined },
  goto:
   { waitUntil: 'networkidle',
     networkIdleTimeout: 2000,
     timeout: undefined,
     networkIdleInflight: undefined },
  pdf:
   { format: 'A4',
     printBackground: true,
     scale: undefined,
     displayHeaderFooter: undefined,
     landscape: undefined,
     pageRanges: undefined,
     width: undefined,
     height: undefined,
     margin:
      { top: undefined,
        right: undefined,
        bottom: undefined,
        left: undefined } },
  url: undefined,
  attachmentName: undefined,
  waitFor: undefined }

When I do a curl command it works as expected, html is null and url contains the expected url.

What am I doing wrong? Thanks in advance!

kimmobrunfeldt commented 6 years ago

Unfortunately I don't have time to help debugging this. url is undefined in the opts, please double check the body format or use GET request with ?url=X query param.