Friday, March 22, 2013

Send a POST request on Google App Engine

To send a request, you need to use Url Fetch service.The URL Fetch service uses Google's network infrastructure for efficiency and scaling purposes.Here is the code to send a simple POST request on Google App Engine :

   public void send(String messageToSend, String date, String level, String servers) {

        try {
            String message = URLEncoder.encode(messageToSend, ENCODING);
            Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyUrl, Integer.parseInt(proxyPort)));

            URL url = new URL(urlDest);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);

            OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
            writer.write("date=" + date);
            writer.write("&level=" + level);
            writer.write("&servers=" + servers);
            writer.write("&msg=" + message);

            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
      "OK ! message returned:" + connection.getResponseCode());
            } else {
      "KO ! message returned:" + connection.getResponseCode());
        } catch (MalformedURLException e) {
        } catch (IOException e) {

I've made a small java project ( 2 class ;-) )that send a simple POST request : See
More details on

No comments:

Post a Comment