I'm doing some work with PyQt4 and QtWebKit, and in the web page request need to send a custom "Host" header along with the standard HTTP request. I'm not seeing any options for adding custom headers to the request, but this is all new to me so I hope I'm missing something. I'm looking here:
http://doc.qt.digia.com/4.6/qwebsettings.html
Any advice would be greatly appreciated.
You can set headers on the QNetworkRequest that is sent:
QNetworkRequest request;
request.setUrl(QUrl("http://qt.nokia.com"));
request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
To use that custom request when loading a page, use the overloaded load function:
myWebView->load(request);
If you want to apply this to all requests QtWebKit makes, you can subclass QNetworkAccessManager and reimplement its createRequest() function to modify headers accordingly.
Related
I'm working on a small-scale instagram scraping project mainly using selenium and the python requests module. I discovered that when the Request Header changes for www.instagram.com, the text that I get from using
requests.get("https://www.instagram.com/<address>/?__a=1")
Returns the HTML code for the webpage. Instead I was expecting it to be the json text containing post details. Currently, it works fine if I change the headers manually.
How do I automatically get the request header using selenium or requests? I'm expecting to get the text labeled in the image attached:
www.instagram.com Request Header
Thank you.
import requests
response = requests.get("https://www.instagram.com/<address>/?__a=1")
print(response.status_code)
print(response.headers)
print(response.json())
As I see in the headers printed out on to console, there is a set-cookie header. If this is something that you are looking for, then you may use this line to extract only this header:
print(resp.headers['Set-Cookie'])
I am unable to get specific data and need you guys' advice on how I can retrieve it.
I am using a curl as a post to submit through an Api in postman and in sucess I only get empty string but the response that I need is there in the headers on the headers tab next to body the image is below
api response shows in headers click for image view
I have used getHeaders and many more functions to get but failed to get anything yet so please guide me that should i do.
Thanks
I am using nsIHttpChannel in an observer to modify outgoing request headers, which works fine. According to the API, however, it appears I cannot simply remove a header (as I can in Chrome), I can only give it an empty value via setEmptyRequestHeader(). Is there some other way to completely remove the header from the request ?
The documentation for setRequestHeader() states
If aValue is empty and aMerge is false, the header will be cleared.
Hi all please help me out with this issue. while I send following http request ("http://xyz/Scribe/Scribe.xsd"); it does not showing any data in response tab in View Result Tree. So please help me out with that.
Thanks.
It's because your server does not return :
Content-Type header
As JMeter uses it to render the response and does not find it, it does not render it.
See:
https://issues.apache.org/bugzilla/show_bug.cgi?id=54226
Issue has now been fixed, you can use nightly build:
http://jmeter.apache.org/nightly.html
I have a WCF Web Api endpoint that returns an invoice: http://localhost/api/invoice/23
The format it returns is that of the accepts header in the request. If the Javascript wants JSON or XML then it just sets this in the accept header. This is how WCF Web Api seems to work. I've added a PDF formatter to invoice so that when asking for application/pdf it will get a rendered pdf file stream back with the appropriate MIME type. This works fine and I can test it in fiddler.
I need the user to click something in the browser to start the PDF download and pop up the open/save dialog. I don't know how to do this and set the accept header of the request. Static links or window.location in javascript won't work because it doesn't let me set the header. AJAX request won't work because although I can set the header, it expects text back and it won't show as a download in the browser.
I'm not sure how I can do this. Any suggestions would be greatly appreciated.
You can just dynamically create a form in JavaScript and ask it to start in a new tab. That should give you what you want.
function SubmitRequest()
{
var myForm = document.createElement("form");
myForm.method = "post";
myForm.action = "url here"
var myInput = document.createElement("input");
myInput.setAttribute("name", "json");
myForm.setAttribute("target", "_blank");
myInput.setAttribute("value", "Your value here");
myForm.appendChild(myInput);
document.body.appendChild(myForm);
myForm.submit();
document.body.removeChild(myForm);
}
The easiest way is to add an A tag in your page with a link to http://localhost/api/invoice/23.pdf and then use the AddUriPathExtensionMapping on your formatter to have it generate the accept header automatically from the path extension on the URI.