[{"data":1,"prerenderedAt":148},["Reactive",2],{"/guides/go/go-resty/accessing-secured-pages":3,"related:ceOoi42ucl":66},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":11,"property":12,"output":13,"related":14,"default":6,"body":17,"_type":61,"_id":62,"_source":63,"_file":64,"_extension":65},"/guides/go/go-resty/accessing-secured-pages","go-resty",false,"","Accessing secured pages","Learn how to access secured pages using Go and the Go-Resty library. This guide offers detailed steps with code samples in Go and the Go-Resty library, highlighting how you can acces page protected by basic authentication to convert them to PDF using PDFShift's API.","Go","Go-Resty","auth","pdf",[15,16],"send-custom-http-headers","using-cookies",{"type":18,"children":19,"toc":58},"root",[20,28,41,53],{"type":21,"tag":22,"props":23,"children":24},"element","p",{},[25],{"type":26,"value":27},"text","In this guide, we'll show you how to access secured page (protected by basic authentication) using Go and the Go-Resty library to convert them to PDF using PDFShift's API.",{"type":21,"tag":22,"props":29,"children":30},{},[31,33,39],{"type":26,"value":32},"When you're converting a document, you might want to access a secured page (protected by basic authentication) to convert it to PDF. This can be done by setting the ",{"type":21,"tag":34,"props":35,"children":37},"code",{"className":36},[],[38],{"type":26,"value":12},{"type":26,"value":40}," parameter to the request.",{"type":21,"tag":42,"props":43,"children":48},"pre",{"className":44,"code":46,"language":47,"meta":7},[45],"language-go","package main\n\nimport (\n    \"encoding/json\"\n    \"fmt\"\n    \"io/ioutil\"\n    \"github.com/go-resty/resty/v2\"\n)\n\nfunc main() {\n    // You can get an API key at https://pdfshift.io\n    apiKey := \"sk_xxxxxxxxxxxx\"\n\n\n    // You can set a basic authentication by passing the \"auth\" property which contains a username and password\n    params := map[string]interface{}{\n        \"source\": \"https://www.example.com\",\n        \"auth\": map[string]string{\n            \"username\": \"user\",\n            \"password\": \"password\",\n        },\n    }\n\n    // Marshal the parameters into JSON\n    jsonParams, err := json.Marshal(params)\n    if err != nil {\n        fmt.Println(\"Error marshaling JSON:\", err)\n        return\n    }\n    // Create a new Resty client\n    client := resty.New()\n\n    // Perform the request\n    resp, err := client.R().\n        SetHeader(\"Content-Type\", \"application/json\").\n        SetHeader(\"X-API-Key\", apiKey).\n        SetBody(jsonParams).\n        Post(\"https://api.pdfshift.io/v3/convert/pdf\")\n\n    if err != nil {\n        fmt.Println(\"Error performing request:\", err)\n        return\n    }\n\n    // Check response status code\n    if resp.StatusCode() >= 400 {\n        fmt.Printf(\"Request failed with status code %d: %s\\n\", resp.StatusCode(), string(resp.Body()))\n        return\n    }\n\n    // Save the PDF document\n    err = ioutil.WriteFile(\"result.pdf\", resp.Body(), 0644)\n    if err != nil {\n        fmt.Println(\"Error saving PDF document:\", err)\n        return\n    }\n\n    fmt.Println(\"The PDF document was generated and saved to result.pdf\")\n}\n","go",[49],{"type":21,"tag":34,"props":50,"children":51},{"__ignoreMap":7},[52],{"type":26,"value":46},{"type":21,"tag":22,"props":54,"children":55},{},[56],{"type":26,"value":57},"This allows you to protect your documents from any visitors while allowing PDFShift to access the page and convert it to PDF.",{"title":7,"searchDepth":59,"depth":59,"links":60},2,[],"markdown","content:guides:go:go-resty:accessing-secured-pages.md","content","guides/go/go-resty/accessing-secured-pages.md","md",[67,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144],{"_path":4,"title":8,"language":10,"library":11,"_id":62},{"_path":69,"title":70,"language":10,"library":11,"_id":71},"/guides/go/go-resty/adding-a-custom-header-or-footer","Adding a custom header or footer","content:guides:go:go-resty:adding-a-custom-header-or-footer.md",{"_path":73,"title":74,"language":10,"library":11,"_id":75},"/guides/go/go-resty/adding-a-text-watermark","Adding a text watermark","content:guides:go:go-resty:adding-a-text-watermark.md",{"_path":77,"title":78,"language":10,"library":11,"_id":79},"/guides/go/go-resty/adding-an-image-watermark","Adding an image watermark","content:guides:go:go-resty:adding-an-image-watermark.md",{"_path":81,"title":82,"language":10,"library":11,"_id":83},"/guides/go/go-resty/avoid-conversion-on-error","Avoid the conversion on error when loading the document","content:guides:go:go-resty:avoid-conversion-on-error.md",{"_path":85,"title":86,"language":10,"library":11,"_id":87},"/guides/go/go-resty/convert-html-to-pdf-from-a-url","Convert an HTML document to PDF from a URL","content:guides:go:go-resty:convert-html-to-pdf-from-a-url.md",{"_path":89,"title":90,"language":10,"library":11,"_id":91},"/guides/go/go-resty/convert-html-to-pdf-from-raw-html","Convert an HTML document to PDF from raw HTML","content:guides:go:go-resty:convert-html-to-pdf-from-raw-html.md",{"_path":93,"title":94,"language":10,"library":11,"_id":95},"/guides/go/go-resty/define-a-time-limit","Define a time limit","content:guides:go:go-resty:define-a-time-limit.md",{"_path":97,"title":98,"language":10,"library":11,"_id":99},"/guides/go/go-resty/exporting-only-a-specific-set-of-pages","Exporting only a specific set of pages","content:guides:go:go-resty:exporting-only-a-specific-set-of-pages.md",{"_path":101,"title":102,"language":10,"library":11,"_id":103},"/guides/go/go-resty/generate-a-document-with-full-height","Generate a document with full height","content:guides:go:go-resty:generate-a-document-with-full-height.md",{"_path":105,"title":106,"language":10,"library":11,"_id":107},"/guides/go/go-resty/loading-css-from-a-string","Loading CSS from a string","content:guides:go:go-resty:loading-css-from-a-string.md",{"_path":109,"title":110,"language":10,"library":11,"_id":111},"/guides/go/go-resty/loading-css-from-a-url","Loading CSS from a URL","content:guides:go:go-resty:loading-css-from-a-url.md",{"_path":113,"title":114,"language":10,"library":11,"_id":115},"/guides/go/go-resty/loading-javascript-from-a-string","Loading Javascript from a string","content:guides:go:go-resty:loading-javascript-from-a-string.md",{"_path":117,"title":118,"language":10,"library":11,"_id":119},"/guides/go/go-resty/loading-javascript-from-a-url","Loading Javascript from a URL","content:guides:go:go-resty:loading-javascript-from-a-url.md",{"_path":121,"title":122,"language":10,"library":11,"_id":123},"/guides/go/go-resty/protecting-the-generated-pdf","Protecting the generated PDF","content:guides:go:go-resty:protecting-the-generated-pdf.md",{"_path":125,"title":126,"language":10,"library":11,"_id":127},"/guides/go/go-resty/receive-a-webhook-event","Receive a webhook event","content:guides:go:go-resty:receive-a-webhook-event.md",{"_path":129,"title":130,"language":10,"library":11,"_id":131},"/guides/go/go-resty/save-your-pdf-online-and-get-back-a-url","Save your PDF online and get back a URL","content:guides:go:go-resty:save-your-pdf-online-and-get-back-a-url.md",{"_path":133,"title":134,"language":10,"library":11,"_id":135},"/guides/go/go-resty/save-your-pdf-to-your-amazon-s3-bucket","Save your PDF to your Amazon S3 Bucket","content:guides:go:go-resty:save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":137,"title":138,"language":10,"library":11,"_id":139},"/guides/go/go-resty/send-custom-http-headers","Send custom HTTP headers","content:guides:go:go-resty:send-custom-http-headers.md",{"_path":141,"title":142,"language":10,"library":11,"_id":143},"/guides/go/go-resty/using-cookies","Using cookies to convert HTML documents to PDF","content:guides:go:go-resty:using-cookies.md",{"_path":145,"title":146,"language":10,"library":11,"_id":147},"/guides/go/go-resty/waiting-for-a-custom-element-to-be-ready","Waiting for a custom element to be ready","content:guides:go:go-resty:waiting-for-a-custom-element-to-be-ready.md",1785426828692]