- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
HTTP in Font
CHAPTER 9 HTTP Generating QR Code JIS X 0510 In None Using Barcode maker for Font Control to generate, create QR Code ISO/IEC18004 image in Font applications. www.OnBarcode.comCreating Barcode In None Using Barcode creator for Font Control to generate, create Barcode image in Font applications. www.OnBarcode.comIdentifying User Agents and Web Servers
Encode Code-39 In None Using Barcode maker for Font Control to generate, create ANSI/AIM Code 39 image in Font applications. www.OnBarcode.comCode 128B Creator In None Using Barcode generation for Font Control to generate, create Code 128B image in Font applications. www.OnBarcode.comYou may have noticed that the HTTP request we opened the chapter with advertised the fact that it was generated by a Python program: User-Agent: Python-urllib/2.6 This header is optional in the HTTP protocol, and many sites simply ignore or log it. It can be useful when sites want to know which browsers their visitors use most often, and it can sometimes be used to distinguish search engine spiders (bots) from normal users browsing a site. For example, here are a few of the user agents that have hit my own web site in the past few minutes: Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm) Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots) Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727) Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.62 Safari/534.3 You will note that, the urllib2 user agent string notwithstanding, most clients choose to identify themselves as some form of the original Netscape browser, whose internal code name was Mozilla. But then, in parentheses, these same browsers secretly admit that they are really some other kind of browser. Many web sites are sensitive to the kinds of browsers that view them, most often because their designers were too lazy to make the sites work with anything other than Internet Explorer. If you need to access such sites with urllib2, you can simply instruct it to lie about its identity, and the receiving web site will not know the difference: >>> url = 'https://wca.eclaim.com/' >>> urllib2.urlopen(url).read() '<HTML>...The following are...required...Microsoft Internet Explorer...' >>> agent = 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)' >>> request = urllib2.Request(url) >>> request.add_header('User-Agent', agent) >>> urllib2.urlopen(request).read() '\r\n<HTML>\r\n<HEAD>\r\n\t<TITLE>Eclaim.com - Log In</TITLE>...' There are databases of possible user agent strings online at several sites that you can reference both when analyzing agent strings that your own servers have received, as well as when concocting strings for your own HTTP requests: http://www.zytrax.com/tech/web/browser_ids.htm http://www.useragentstring.com/pages/useragentstring.php Besides using the agent string to enforce compatibility requirements usually in an effort to reduce development and support costs some web sites have started using the string to detect mobile browsers and redirect the user to a miniaturized mobile version of the site for better viewing on phones and iPods. A Python project named mobile.sniffer that attempts to support this technique can be found on the Package Index. Encoding GS1 - 12 In None Using Barcode creation for Font Control to generate, create GTIN - 12 image in Font applications. www.OnBarcode.comDrawing Quick Response Code In None Using Barcode maker for Font Control to generate, create QR Code ISO/IEC18004 image in Font applications. www.OnBarcode.comCHAPTER 9 HTTP
GS1-128 Generator In None Using Barcode creator for Font Control to generate, create GS1-128 image in Font applications. www.OnBarcode.comMake EAN8 In None Using Barcode drawer for Font Control to generate, create EAN-8 Supplement 2 Add-On image in Font applications. www.OnBarcode.comContent Type Negotiation
QR-Code Generator In None Using Barcode generation for Software Control to generate, create QR Code JIS X 0510 image in Software applications. www.OnBarcode.comQuick Response Code Drawer In Visual Studio .NET Using Barcode encoder for Reporting Service Control to generate, create QR Code 2d barcode image in Reporting Service applications. www.OnBarcode.comIt is always possible to simply make an HTTP request and let the server return a document with whatever Content-Type: is appropriate for the information we have requested. Some of the usual content types encountered by a browser include the following: text/html text/plain text/css image/gif image/jpeg image/x-png application/javascript application/pdf application/zip If the web service is returning a generic data stream of bytes that it cannot describe more specifically, it can always fall back to the content type: application/octet-stream But some clients do support all content types. Such clients like to encourage servers to send compatible content when several versions of a resource are available. This selection can occur along several axes: older browsers might not know about new, up-and-coming image formats; some browsers can only read certain encodings; and, of course, each user has particular languages that she can read and prefers web sites to deliver content in her native tongue, if possible. Consult RFC 2616 if you find that your Python web client is sophisticated enough that you need to wade into content negotiation. The four headers that will interest you include the following: Accept Accept-Charset Accept-Language Accept-Encoding Each of these headers supports a comma-separated list of items, where each item can be given a weight between one and zero (larger weights indicate more preferred items) by adding a suffix that consists of a semi-colon and q= string to the item. The result will look something like this (using, for illustration, the Accept: header that my Google Chrome browser seems to be currently using): Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain; q=0.8,image/png,*/*;q=0.5 This indicates that Chrome prefers XML and XHTML, but will accept HTML or even plain text if those are the only document formats available; that Chrome prefers PNG images when it can get them; and that it has no preference between all of the other content types in existence. The HTTP standard also describes the possibility of a client receiving a 300 Multiple Choices response and getting to choose its own content type; however, this does not seem to be a widelyimplemented mechanism, and I refer you to the RFC should you ever need to use it. Create EAN13 In .NET Framework Using Barcode printer for .NET Control to generate, create EAN / UCC - 13 image in .NET applications. www.OnBarcode.comMake Barcode In VS .NET Using Barcode maker for .NET Control to generate, create Barcode image in Visual Studio .NET applications. www.OnBarcode.comPrinting Barcode In None Using Barcode generator for Software Control to generate, create Barcode image in Software applications. www.OnBarcode.comEAN / UCC - 13 Generator In Java Using Barcode maker for Java Control to generate, create UPC - 13 image in Java applications. www.OnBarcode.comEncoding GTIN - 128 In Objective-C Using Barcode generation for iPad Control to generate, create EAN / UCC - 14 image in iPad applications. www.OnBarcode.comDenso QR Bar Code Maker In Objective-C Using Barcode generation for iPad Control to generate, create QR image in iPad applications. www.OnBarcode.comPDF-417 2d Barcode Decoder In Visual Basic .NET Using Barcode decoder for .NET Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comGenerating UCC.EAN - 128 In None Using Barcode generator for Online Control to generate, create USS-128 image in Online applications. www.OnBarcode.comGenerating Barcode In None Using Barcode creator for Microsoft Word Control to generate, create Barcode image in Word applications. www.OnBarcode.comCode 3/9 Generation In Java Using Barcode creator for Android Control to generate, create Code-39 image in Android applications. www.OnBarcode.com |
|