[{"data":1,"prerenderedAt":101},["Reactive",2],{"/guides/java/retrofit/accessing-secured-pages":3,"/guides/java/retrofit/accessing-secured-pages-related":67},{"_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":17,"body":18,"_type":62,"_id":63,"_source":64,"_file":65,"_extension":66},"/guides/java/retrofit/accessing-secured-pages","retrofit",false,"","Accessing secured pages","Learn how to access secured pages using Java and the Retrofit library. This guide offers detailed steps with code samples in Java and the Retrofit library, highlighting how you can access page protected by basic authentication to convert them to PDF using PDFShift's API.","Java","Retrofit","auth","pdf",[15,16],"send-custom-http-headers","using-cookies",true,{"type":19,"children":20,"toc":59},"root",[21,29,42,54],{"type":22,"tag":23,"props":24,"children":25},"element","p",{},[26],{"type":27,"value":28},"text","In this guide, we'll show you how to access secured page (protected by basic authentication) using Java and the Retrofit library to convert them to PDF using PDFShift's API.",{"type":22,"tag":23,"props":30,"children":31},{},[32,34,40],{"type":27,"value":33},"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":22,"tag":35,"props":36,"children":38},"code",{"className":37},[],[39],{"type":27,"value":12},{"type":27,"value":41}," parameter to the request.",{"type":22,"tag":43,"props":44,"children":49},"pre",{"className":45,"code":47,"language":48,"meta":7},[46],"language-java","import retrofit2.*;\nimport retrofit2.converter.gson.GsonConverterFactory;\nimport com.google.gson.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\npublic interface PdfShiftApi {\n    @POST(\"v3/convert/pdf\")\n    Call\u003CResponseBody> convertToPdf(\n        @Header(\"X-API-Key\") String apiKey,\n        @Body JsonObject body\n    );\n}\n\n// Usage\nGson gson = new GsonBuilder().create();\nRetrofit retrofit = new Retrofit.Builder()\n    .baseUrl(\"https://api.pdfshift.io/\")\n    .addConverterFactory(GsonConverterFactory.create(gson))\n    .build();\n\nPdfShiftApi api = retrofit.create(PdfShiftApi.class);\n\nJsonObject payload = new JsonObject();\npayload.addProperty(\"source\", \"https://www.example.com\");\nJsonObject auth = new JsonObject();\nauth.addProperty(\"username\", \"user\");\nauth.addProperty(\"password\", \"password\");\npayload.add(\"auth\", auth);\n\nCall\u003CResponseBody> call = api.convertToPdf(\"sk_xxxxxxxxxxxx\", payload);\nResponse\u003CResponseBody> response = call.execute();\n\n// Handle errors:\nif (!response.isSuccessful()) {\n    throw new IOException(\"Request failed with status code \" + response.code());\n}\n\nResponseBody responseBody = response.body();\nif (responseBody != null) {\n    java.nio.file.Files.write(\n        java.nio.file.Paths.get(\"result.pdf\"), \n        responseBody.bytes()\n    );\n}\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n","java",[50],{"type":22,"tag":35,"props":51,"children":52},{"__ignoreMap":7},[53],{"type":27,"value":47},{"type":22,"tag":23,"props":55,"children":56},{},[57],{"type":27,"value":58},"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":60,"depth":60,"links":61},2,[],"markdown","content:guides:java:retrofit:accessing-secured-pages.md","content","guides/java/retrofit/accessing-secured-pages.md","md",[68,69,73,77,81,85,89,93,97],{"_path":4,"title":8,"language":10,"library":11,"_id":63},{"_path":70,"title":71,"language":10,"library":11,"_id":72},"/guides/java/retrofit/adding-a-custom-header-or-footer","Adding a custom header or footer","content:guides:java:retrofit:adding-a-custom-header-or-footer.md",{"_path":74,"title":75,"language":10,"library":11,"_id":76},"/guides/java/retrofit/adding-a-text-watermark","Adding a text watermark","content:guides:java:retrofit:adding-a-text-watermark.md",{"_path":78,"title":79,"language":10,"library":11,"_id":80},"/guides/java/retrofit/adding-an-image-watermark","Adding an image watermark","content:guides:java:retrofit:adding-an-image-watermark.md",{"_path":82,"title":83,"language":10,"library":11,"_id":84},"/guides/java/retrofit/avoid-conversion-on-error","Avoid conversion on error","content:guides:java:retrofit:avoid-conversion-on-error.md",{"_path":86,"title":87,"language":10,"library":11,"_id":88},"/guides/java/retrofit/convert-html-to-pdf-from-a-url","Convert HTML to PDF from a URL","content:guides:java:retrofit:convert-html-to-pdf-from-a-url.md",{"_path":90,"title":91,"language":10,"library":11,"_id":92},"/guides/java/retrofit/convert-html-to-pdf-from-raw-html","Convert HTML to PDF from raw HTML","content:guides:java:retrofit:convert-html-to-pdf-from-raw-html.md",{"_path":94,"title":95,"language":10,"library":11,"_id":96},"/guides/java/retrofit/define-a-time-limit","Define a time limit","content:guides:java:retrofit:define-a-time-limit.md",{"_path":98,"title":99,"language":10,"library":11,"_id":100},"/guides/java/retrofit/exporting-only-a-specific-set-of-pages","Exporting only a specific set of pages","content:guides:java:retrofit:exporting-only-a-specific-set-of-pages.md",1780405109587]