Set cookie when sending request using cURL - javascript

There is an external website A (not mine) which provides a PDF document after filling an HTML form.
Here is the scenario when I do the procedure on site A :
I open my Internet browser on the site A homepage (I will call this
page A1), then a JESSIONID is created into my browser's cookie
I fill the form on a page A2
if the form is correctly filled, i am redirected to a page A3,
from which a link is available to download a PDF file, using url :
A.com/getPdf.jsp
I now want to allow users to dowload this PDF file from my website B, using my own form.
To do so :
step 1 : I am sending the form inputs to website A using PHP cURL.
This step is working successfully, and I got a JSESSIONID reference.
step 2 : then I am opening a window from my website using URL :
A.com/getPdf.jsp
But it does not provide me the needed document as the session state is not maintained between previous steps 1 and 2...
So my question is to know how can I call A.com/getPdf.jsp URL, using the same state (same JESSIONID) than the one I retrieved just before from the cURL request?
Thanks in advance for your suggestions.

Related

Laravel snappy pushing PDF download

I am using Laravel/Jquery with barryvdh/laravel-snappy to create a pdf on the fly from database data.
In the controller I have:
if ($request->ajax())
{
$document = Document::url($id)->first();
$pdf = PDF::loadView('app.documents.whitepapers.pdf', compact('document'));
return $pdf->download('filename.pdf');
// return response()->send($pdf->download('filename.pdf'), 200, $headers);
}
How can I push this PDF to the browser so that is available as a download?
When I do it without Jquery it is working perfectly. The reason that it is behind a Jquery function is that I use a Modal with a form to collect a persons data before the download can be initiated. This has ajax validation.
You will not be able to present the file as a regular download via JavaScript. In order to show a download prompt to the user, you'll need an extra step in your workflow.
I would suggest the following workflow:
User submits modal form
Form is validated via AJAX. If validation passes, respond with a URL to download the user's PDF from, instead of the PDF itself.
Your JavaScript redirects the user to this URL. Note that this is a redirect, rather than another AJAX request (see top.location.href)
When the user accesses that URL, you are able to deliver the PDF using the code snippet you provided in your original question. This snippet sets the content-disposition of the response appropriately, forcing the download prompt to appear in the user's browser.
If you need to customise the PDF generation for each user, make sure to include the user's ID (or another piece of identifying information) through to step 4.

Acrobat Javascript: passing a UTM parameter from URL into a PDF button

I have a PDF that has a button with field name ctaButton.
ctaButton currently has a url pointing to https://mywebsite.com.
I want to host the PDF on my server at https://mywebsite.com/hosted.pdf.
And when I send someone a link to the PDF, I want to attach a UTM_term parameter ?utm_term=customer1 and then have the PDF read this parameter and update the ctaButton url to https://mywebsite.com/?utm_term=customer1.
I've been messing around with the Javascript actions in Acrobat for a couple of hours trying to make this happen. Any help greatly appreciated.
You can get the full url to the document using...
var myURL = this.url;
"this" in Acrobat JavaScript is the document context.
I did hours of research and came to this conclusion – Javascript in Acrobat is like trying to code in 1985 AND browsers will not execute whatever code you come up with.
So I used this workaround:
When I send the PDF to someone, I send it as a link with a base64
encoded stringified JSON package that contains a bunch of tracking
data but importantly, the name of the file to access as well as utm
parameters specific to the recipient
The link hits a server handler (NodeJS) that extracts the encoded
JSON package, and uses the data in the package to serve up an HTML
redirect page pointing to the right PDF file
Importantly, the HTML page also saves the JSON package to the
browser's localStorage . . . this comes in handy in subsequent
steps
The PDF file opens in browser (it doesn't have to, could be opened on
desktop) and the call to action link has a link to a get request
handler
The get request handler serves up ANOTHER redirect page
This second redirect page accesses the browser's local storage, looks
for the utm parameters I set for that user, and then redirects to the
sale page, with nice utm parameters attached
So to sum up, you don't add the utm parameters to the call to action link in the PDF (because that would make the world too easy to live in) and instead you do all these acrobatics (no pun intended) to attach utm parameters in the link clicks (via JSON strings saved in localStorage) during the process (i.e. when user opens email to extract file via link, and then when user clicks call to action in the PDF).
Any questions or clarifications please let me know in the comments and I will do my best to address.
Caveats
Only works if user uses same browser in all steps (i.e. if Susan opens the email in Safari, saves the PDF, then clicks the call to action in the PDF, and the link opens in Chrome, utm parameters will not be passed).
Assumes browser is modern and has localStorage
UPDATE: I came across another solution. It's a bit more convoluted. Diagram below.
Porky.io is a Javascript extension for Adobe Indesign. So flow is:
send Porky.io the customer data you need (e.g. utm's for links)
Porky.io generates PDF from a template you provide with the customer data you provided
Listen for a new file save from Porky
Do something with the file (e.g. email it to customer)
I believe you need to run an instance of Windows somewhere in the cloud (e.g. on Azure) to run Indesign with the Porky.io. Unless you want to rely on your laptop.
My project's not big enough yet to warrant setting this up . . . but good alternative if I need to make my current solution more robust.

load remote content that need authentication?

This is the scenario :
-User is logged in the remote website (via iframe)
-With that cookie saved the user is able to make a get request and obtain a table
-This table is loaded in a second iframe
Problem : I would like to apply styles to that received information.
The output of the request is a simple html file with a table , I cannot access that file from a server (php for example) , because I have no control over the remote site , and in order to make that request user need to be logged (and as said what I do is load an iframe with the get request response..) .
The only thing that comes to my mind is to parse that response , but without a server-side tool , I do not think this is approachable. Any idea?

Refresh the browser cache for same call to an event updated file

Here is my scenario
Asp. net website
Angular app embedded via IFrame
First user clicks on the .net button that saves a response in a .csv file on the server. On every click different data is updated on the file
Then user clicks on the angular page, which gets the data from that file using a link.
Now the issue is with the caching. Because every time the same link is referred thus, browser shows the data from the previous request and don't actually read the updated file.
The reason I know it is caching issue is because, when I open it on fresh browser I see the updated content. After I run it second time with different request, again it shows me the same data
I have already tried
$http.get(url, {cache: false}
Response.Cache.SetCacheability(HttpCacheability.NoCache);
on my aspx page_load function.
How can I make it to read the updated file? Any help will be appreciated
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Put this code in page load. Now there will be no data in cache browser will try to get the page from the server
Unfortunately I could not found any solution to my problem thus I have changed the logic.
Following is what I am doing now which is perfectly working:
1 Asp. net website
2 Angular app embedded via IFrame
3 First user clicks on the .net button that saves a response in a .csv file on the server. On every click different data is updated on the file. So, I am adding a function that adds the time stamp to name of file on each click
4 Sending the file to the client script via query string hash value . Adding the name of the file as hash value
5 At client side using $scope.$watch, watching the url and on each url change, gets the file name and loads the data from the location.
Now I am facing one more problem which is over here:
Add hash to the current url without reload in c#
If, anyone can help me with that?
Thanks

can i post some data to a jsp web form using javascript code?

I have with me javascript code that is able to authenticate users with Windows Live Authentication. After logon, a simple message is displayed to the user.
What I want is that the message is displayed to the user for 10 seconds, and after that the email ID of user plus a flag that indicates successful login, are posted to a jsp page which is opened in the same browser window... Can this be done using Javascript or some other way?
If it is not possible to pass these values to a jsp form, alternatively can these values be stored in jsp session variables (so that other JSPs are able to use these values)?
Thanks,
Arvind.
You can do it by using
location.replace("resultPage.jsp?emailId="+emailID+"success=true");
Now you can access these values using:
request.getParameter("emailId");
request.getParameter("success");

Categories