Can I set the host language header, but not the connection header? PhantomJS (Selenium Webdriver with Python)

I can set the Accept-Language header, but somehow I cannot set the Connection header to "keep-alive":

from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.Accept-Language'] = 'ru-RU' webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.Connection'] = "keep-alive" driver = webdriver.PhantomJS("/home/user/bin/phantomjs",service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any']) driver.set_window_size(1120, 550) driver.get("http://www.httpbin.org/headers") print(driver.page_source) 

Exit

 <html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">{ "headers": { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "ru-RU", "Host": "www.httpbin.org", "User-Agent": "Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1" } } </pre></body></html> 

I thought that, for some reason, the header or fields themselves were case sensitive, so I looked at examples of these headers and used them exactly as they were, but without the dice. How to set connection header or keep-alive header?

+6
source share
1 answer

It looks like the default header for connecting phantomjs is Keep-alive, the site you use to view the headers doesn't display the Connection header, even if it doesn't use PhantomJS. If you look at your request using Fiddler, you will see that it has a keep-alive connection header

GET / headers HTTP / 1.1 Accept: text / html, application / xhtml + xml, application / xml; q = 0.9, /; q = 0.8
User-Agent: Mozilla / 5.0 (Windows NT 6.1, WOW64) AppleWebKit / 538.1 (KHTML, e.g. Gecko) PhantomJS / 2.1.1 Safari / 538.1

Connection: Keep-Alive

Accept-Encoding: gzip, deflate Accept-Language: en-US, * Host: www.httpbin.org

+2
source

All Articles