http HEAD vs GET performance

A RESTful URI should represent a “resource” at the server. Resources are often stored as a record in a database or a file on the filesystem. Unless the resource is large or is slow to retrieve at the server, you might not see a measurable gain by using HEAD instead of GET. It could be … Read more

Writing image to local server

A few things happening here: I assume you required fs/http, and set the dir variable 🙂 google.com redirects to www.google.com, so you’re saving the redirect response’s body, not the image the response is streamed. that means the ‘data’ event fires many times, not once. you have to save and join all the chunks together to … Read more

HttpPost vs HttpGet attributes in MVC: Why use HttpPost?

Imagine the following: [HttpGet] public ActionResult Edit(int id) { … } [HttpPost] public ActionResult Edit(MyEditViewModel myEditViewModel) { … } This wouldn’t be possible unless the ActionMethodSelectorAttributes HttpGet and HttpPost where used. This makes it really simple to create an edit view. All the action links just points right back to the controller. If the view … Read more

HTTP GET in VB.NET

In VB.NET: Dim webClient As New System.Net.WebClient Dim result As String = webClient.DownloadString(“http://api.hostip.info/?ip=68.180.206.184”) In C#: System.Net.WebClient webClient = new System.Net.WebClient(); string result = webClient.DownloadString(“http://api.hostip.info/?ip=68.180.206.184”);

Standardized way to serialize JSON to query string?

URL-encode (https://en.wikipedia.org/wiki/Percent-encoding) your JSON text and put it into a single query string parameter. for example, if you want to pass {“val”: 1}: mysite.com/path?json=%7B%22val%22%3A%201%7D Note that if your JSON gets too long then you will run into a URL length limitation problem. In which case I would use POST with a body (yes, I know, … Read more

Hit a bean method and redirect on a GET request

Use <f:viewAction> to trigger a bean method before rendering of the view and simply return a navigation outcome (which will implicitly be treated as a redirect). E.g. <f:metadata> <f:viewParam name=”token” value=”#{authenticator.token}” /> <f:viewAction action=”#{authenticator.check}” /> </f:metadata> with @ManagedBean @RequestScoped public class Authenticator { private String token; public String check() { return isValid(token) ? null : … Read more