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

HTTP Status 405 – HTTP method is not supported by this URL

This is the default response of the default implementation of HttpServlet#doXxx() method (doGet(), doPost(), doHead(), doPut(), etc). This means that when the doXxx() method is not properly being @Overriden in your servlet class, or when it is explicitly being called via super, then you will face a HTTP 405 “Method not allowed” error. So, you … Read more

How to add parameters to a HTTP GET request in Android?

I use a List of NameValuePair and URLEncodedUtils to create the url string I want. protected String addLocationToUrl(String url){ if(!url.endsWith(“?”)) url += “?”; List<NameValuePair> params = new LinkedList<NameValuePair>(); if (lat != 0.0 && lon != 0.0){ params.add(new BasicNameValuePair(“lat”, String.valueOf(lat))); params.add(new BasicNameValuePair(“lon”, String.valueOf(lon))); } if (address != null && address.getPostalCode() != null) params.add(new BasicNameValuePair(“postalCode”, address.getPostalCode())); if … Read more

When submitting a GET form, the query string is removed from the action URL

Isn’t that what hidden parameters are for to start with…? <form action=”http://www.example.com” method=”GET”> <input type=”hidden” name=”a” value=”1″ /> <input type=”hidden” name=”b” value=”2″ /> <input type=”hidden” name=”c” value=”3″ /> <input type=”submit” /> </form> I wouldn’t count on any browser retaining any existing query string in the action URL. As the specifications (RFC1866, page 46; HTML 4.x … Read more