How to make an HTTP get request in C without libcurl?

Using BSD sockets or, if you’re somewhat limited, say you have some RTOS, some simpler TCP stack, like lwIP, you can form the GET/POST request. There are a number of open-source implementations. See the “happyhttp” as a sample ( http://scumways.com/happyhttp/happyhttp.html ). I know, it is C++, not C, but the only thing that is “C++-dependant” … Read more

Getting HTTP code in PHP using curl

First make sure if the URL is actually valid (a string, not empty, good syntax), this is quick to check server side. For example, doing this first could save a lot of time: if(!$url || !is_string($url) || ! preg_match(‘/^http(s)?:\/\/[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(\/.*)?$/i’, $url)){ return false; } Make sure you only fetch the headers, not the body content: @curl_setopt($ch, … Read more

Parse raw HTTP Headers

Update: It’s 2019, so I have rewritten this answer for Python 3, following a confused comment from a programmer trying to use the code. The original Python 2 code is now down at the bottom of the answer. There are excellent tools in the Standard Library both for parsing RFC 821 headers, and also for parsing … Read more

Content-Length header with HEAD requests?

To me it looks like the HTTP 1.1 RFC is pretty specific: The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET.

Are Duplicate HTTP Response Headers acceptable?

Yes HTTP RFC2616 available here says: Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one “field-name: field-value” pair, without changing … Read more

Setting a cookie using JavaFX’s WebEngine/WebView

I have managed to solve this issue with the help of Vasiliy Baranov from Oracle. Vasiliy wrote to me: Try putting the cookie into java.net.CookieHandler.getDefault() after the WebView is instantiated for the first time and before the call to WebEngine.load, e.g. as follows: WebView webView = new WebView(); URI uri = URI.create(“http://mysite.com”); Map<String, List<String>> headers … Read more

Check if PHP-page is accessed from an iOS device

Use the user agent from $_SERVER[‘HTTP_USER_AGENT’], and for simple detection you can use this script: <?php //Detect special conditions devices $iPod = stripos($_SERVER[‘HTTP_USER_AGENT’],”iPod”); $iPhone = stripos($_SERVER[‘HTTP_USER_AGENT’],”iPhone”); $iPad = stripos($_SERVER[‘HTTP_USER_AGENT’],”iPad”); $Android = stripos($_SERVER[‘HTTP_USER_AGENT’],”Android”); $webOS = stripos($_SERVER[‘HTTP_USER_AGENT’],”webOS”); //do something with this information if( $iPod || $iPhone ){ //browser reported as an iPhone/iPod touch — do something here … Read more