HTTP headers in Websockets client API

Updated 2x Short answer: No, only the path and protocol field can be specified. Longer answer: There is no method in the JavaScript WebSockets API for specifying additional headers for the client/browser to send. The HTTP path (“GET /xyz”) and protocol header (“Sec-WebSocket-Protocol”) can be specified in the WebSocket constructor. The Sec-WebSocket-Protocol header (which is … Read more

How to use HTML to print header and footer on every printed page of a document?

If you take the element that you want to be the footer and set it to be position:fixed and bottom:0, when the page prints it will repeat that element at the bottom of each printed page. The same would work for a header element, just set top:0 instead. For example: <div class=”divFooter”>UNCLASSIFIED</div> CSS: @media screen … Read more

Parsing CSV files in C#, with header

A CSV parser is now a part of .NET Framework. Add a reference to Microsoft.VisualBasic.dll (works fine in C#, don’t mind the name) using (TextFieldParser parser = new TextFieldParser(@”c:\temp\test.csv”)) { parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(“,”); while (!parser.EndOfData) { //Process row string[] fields = parser.ReadFields(); foreach (string field in fields) { //TODO: Process field } } } … Read more

Returning JSON from a PHP Script

While you’re usually fine without it, you can and should set the Content-Type header: <?php $data = /** whatever you’re serializing **/; header(‘Content-Type: application/json; charset=utf-8′); echo json_encode($data); If I’m not using a particular framework, I usually allow some request params to modify the output behavior. It can be useful, generally for quick troubleshooting, to not … Read more