Save html page after JSON - AJAX post request - c++

I use curl in C++ to download an html page from a website, then I save it.
After I've saved the html file, with another programm I've to read it, and save it in a string.
This page contain some request (POST) made by JSON-AJAX. If I open it with the broswer I have the right content. If I open it with a text editor I have a bad content because the POST request is not made.
So how can I save the page whit the content obtained after JSON-AJAX request??

Curl will download the HTML code from the page and that's it. When you open the HTML file with a web browser, the browser is taking care of whatever post request is being sent.
You need to find out what the post request contains (i.e., the data and how it's obtained) and send that request separately and save the response.
You might want to look into this question How do you make a HTTP request with C++?

Related

Coldfusion cfcontent doesn't take me back to my calling page

I'm calling this from a .cfm page to download the excel file and I have added a loading mask to prevent further clicks on the download button, however, once after downloading it doesn't go back to my .cfm page and never stops the loading masks.
cfheader( name="Content-Disposition", value="attachment; filename=#fileName#" );
cfcontent( type="application/vnd.ms-excel", variable="#spreadsheetReadBinary(spreadsheet)#", reset="true" );
Any help would be appreciated. Thanks!
You're not going to get to any redirect command when using cfcontent. The response from that command is based on the mime-type of the requested content.
application/json
application/xml
application/vnd.ms-excel
You don't get anything other than that content. In your case, once the file is downloaded, then no more CFML code is run on the page.
If your desired workflow is:
Click a link
Download file
Redirect once the file is downloaded.
then you should
Click a link that triggers a fetch request (or jQuery.ajax())
The download will be done via a separate page.
The fetch can redirect to another page once the file is downloaded.
Odds are, you don't need to actually redirect, you just want the file to download
(Sorry, this has been sitting not posted for a few days.)

Qt GET request strange response

I'm writing a program to log into a game a get some information from the account.
After making a post request with username and password, I make a get request in the same location in order to download the needed html source.
However, doing qDebug()<<QString(reply->readAll());
prints "\u001F?\b" ,instead of the entire source code of the page.
The get reply has status code 200, and the error() function returns NetworkError(NoError).
For the post and get requests I'm using header information obtained from chrome's network tab in developer options combined with cookies obtained from previous response headers.
I'm doing a get request after the log-in post request because that's what seems to happen in the actual webpage, as displayed in developer options.
The response might be gzipped. Does unzipping happen to yield the expected result?

What's the http request for the page source?

I've managed to make a file downloader in C++ (using winsock). It downloads every simple link with a file like: www.page.com/image.png
I want to make it download all of the images from an entire page, such as all the images from a 4chan thread, but I don't know what I should send in the http request to get the page's source. How can I request the source of a webpage?
You don't send anything in the http request, in the manner you're thinking.
An http request sends a single request, for a single document, and returns a single document from the server.
To download an entire page, you will have to parse the downloaded HTML document, extract all the relative links from the HTML source, then issue a separate http request for every image, css, js, etc... referenced from the main document.
This is how tools like wget's --recursive option download entire pages.
If the page is located at the root of the http://www.page.com server, you would send a GET request to the www.page.com server asking for the / resource:
GET / HTTP/1.1
Host: www.page.com
Let's say the page was actually located at http://www.page.com/thepage.html. You would send a GET request asking for /thepage.html instead:
GET /thepage.html HTTP/1.1
Host: www.page.com
Either way, you would then have to parse the resulting HTML to get the individual URLs of all the <img> tags that are on the page.

ajax request not sent in IE6

I am developing a webpage with all actions handled as ajax.It works fine in firefox,IE 8,7.But in IE 6 no request is being sent to the sever.Why does this happen.I amusing jquery.getjson and jquery.colourbox methods to fetch data and display in colorbox.
Change Password<span class=""></span> $('a.changepass').colorbox();
This is the html code and i need to open the contents of returned response in colorbox.This works fine with IE 7,8 and firefox.
I guess, this maybe a cache problem.
IE try caching everything requested from a url.
if u request the same url for 2nd time, ie will return the old data by 1st request without any network.
to solv ie's url cache, adding a "?" or current timestamp param to request url.
http://abc.com/ajax?t=123455
Have you read this about the UTF-8?
http://firelitdesign.blogspot.com/2009/07/jquerys-getjson.html

api request returns json files and not html/xml browser content

I am sending get httpwebrequests to the facebook graph api and all was working fine till I deployed to production server and now module that expects html/xml response is not working and when tested url in internet explorer, the save file dialog pops up and the file needs to be saved.
Other modules also send requests to the facebook graph but just differ in the form of requests so not sure what is going on here.
Any ideas appreciated
Edit:
Let me try and rephrase this. On my production server the httpwebrequest was not returning the correct result. So to Test it I copied the url http://graph.facebook.com/pepsi which is an example, should return the profile info viewable in the browser. The server has internet explorer v8 and I am not sure why it tries to download the file instead of displaying it in the browser. this is what is happening in my code and when I make a request to a different part of the api, then it works in my app but not in the browser
Your question is not very clear. From what I gather, you want the display the JSON response in a browser. Instead, you are being asked to download a file by the browser.
Well, this is normal behaviour. The response you get from Facebook would most likely have a MIME type of application/json. Most newer web browsers display the text in the browser itself. Some browsers, however don't know how to handle this content type and just ask you to download the file.
You mentioned that your module expects an html/xml response. Try changing this to application/json.
You also said that it works in your app but not in your browser. I don't know what you're making, but generally you wouldn't show raw json to the user in a browser, right?