Using Curl, you can take full advantage of PhantomJsCloud by making HTTP Post Requests to our HTTP Endpoint. Below are some examples outlining how to invoke the HTTP Endpoint from Curl.
502 (Bad Gateway) Errors IMPORTANT
Curl sets the Expect:true header by default. You must unset
this or you will get 502 Bad Gateway errors with your curl
requests.
The errors won't occur when your POST payload is small, but medium and large POST payloads
will always get this 502 error.
See the below examples for how to properly make curl calls. (Pass the
-H "Expect:" argument to curl).
request.json)
In the following example Curl request POST body, we submit a
request.json file.
This file follows either the UserRequest or PageRequest specification,
which can be viewed from our HTTP Endpoint docs.
The default parameters (for pageRequest parameters you do not explicitly set) can be viewed here.
request.json{
"url":"http://example.com",
"renderType":"plainText"
}
command-linecurl -v -k -H "Content-Type: application/json" -H "Expect:" -X POST -d @request.json "https://PhantomJScloud.com/api/browser/v2/a-demo-key-with-low-quota-per-ip-address/"
request.json{
"url":"http://example.com",
"renderType":"plainText",
"outputAsJson":true
}
command-linecurl -v -k -H "Content-Type: application/json" -H "Expect:" -X POST -d @request.json "https://PhantomJScloud.com/api/browser/v2/a-demo-key-with-low-quota-per-ip-address/" -o capture.json
request.json{
"url":"http://www.highcharts.com/stock/demo/intraday-area",
"renderType":"jpeg"
}
command-linecurl -v -k -H "Content-Type: application/json" -H "Expect:" -X POST -d @request.json "https://PhantomJScloud.com/api/browser/v2/a-demo-key-with-low-quota-per-ip-address/" -o capture.jpg
request.json{
"url":"https://amazon.com",
"renderType":"pdf"
}
command-linecurl -v -k -H "Content-Type: application/json" -H "Expect:" -X POST -d @request.json "https://PhantomJScloud.com/api/browser/v2/a-demo-key-with-low-quota-per-ip-address/" -o capture.pdf
request.json{
"pages":[
{
"url": "http://example.com",
"content": null,
"urlSettings": {
"operation": "GET",
"encoding": "utf8",
"headers": {},
"data": null
},
"renderType": "jpg",
"outputAsJson": false,
"requestSettings": {
"ignoreImages": false,
"disableJavascript": false,
"userAgent": "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) Safari/534.34 PhantomJS/2.0.0 (PhantomJsCloud.com/2.0.1)",
"authentication": {
"userName": "guest",
"password": "guest"
},
"xssAuditingEnabled": false,
"webSecurityEnabled": false,
"resourceWait": 15000,
"resourceTimeout": 35000,
"maxWait": 35000,
"waitInterval": 1000,
"stopOnError": false,
"resourceModifier": [],
"customHeaders": {},
"clearCache": false,
"clearCookies": false,
"cookies": [],
"deleteCookies": []
},
"suppressJson": [
"events.value.resourceRequest.headers",
"events.value.resourceResponse.headers",
"frameData.content",
"frameData.childFrames"
],
"renderSettings": {
"quality": 70,
"pdfOptions": {
"border": null,
"footer": {
"firstPage": null,
"height": "1cm",
"lastPage": null,
"onePage": null,
"repeating": "%pageNum%/%numPages%"
},
"format": "letter",
"header": null,
"height": null,
"orientation": "portrait",
"width": null
},
"clipRectangle": null,
"renderIFrame": null,
"viewport": {
"height": 1280,
"width": 1280
},
"zoomFactor": 1,
"passThroughHeaders": false
},
"scripts": {
"domReady": [],
"loadFinished": []
}
}
],
"proxy":false
}
command-linecurl -v -k -H "Content-Type: application/json" -H "Expect:" -X POST -d @request.json "https://PhantomJScloud.com/api/browser/v2/a-demo-key-with-low-quota-per-ip-address/" -o capture.jpg
Check out the Advanced Scenario Samples section of the Docs Index Page for Page Automation, Auto-Login, and more.