title: POSTing JSON and retrieving a response in Android
body: <p>I am trying to post a JSON message to a site and to retrieve a JSON message back.<br>
  java.net.ProtocolException: method does not support a request body: POST
  Does anyone know what is wrong?  Thanks in advance</p>
  
  <pre><code>                 HttpURLConnection conn=null;
          try{
              URL url=new URL(urlString);
              String userPassword = userName +":" + passWord;
              byte[] bytes=Base64.encode(userPassword.getBytes(),Base64.DEFAULT);
              String stringEncoding = new String(bytes, "UTF-8");
  
               conn = (HttpURLConnection) url.openConnection();
               conn.setReadTimeout(10000 /* milliseconds */);
               conn.setConnectTimeout(15000 /* milliseconds */);
               conn.setDoOutput(true);
               conn.setDoInput(true);
               conn.setRequestMethod("POST");
              conn.setRequestProperty ("Authorization", "Basic " + stringEncoding);
              conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
              Log.i("Net", "length="+conn.getContentLength());
              Log.i("Net", "contentType="+conn.getContentType());
              Log.i("Net", "content="+conn.getContent());
              conn.connect();
  
          }catch(Exception e){
              Log.d("Url Formation Connection", e.toString());
          } 
  </code></pre>
  
  <p>//output{
              try{</p>
  
  <pre><code>            String requestString="{“ ";
  
  
              wr = new OutputStreamWriter(conn.getOutputStream());
              wr.write(requestString.toString());
              wr.flush();
  
      //input{
          BufferedReader rd = null;
          String response=" ";
  
  
              is = conn.getInputStream();
              rd = new BufferedReader(new InputStreamReader(is));
              String line;
              StringBuffer responseBuff = new StringBuffer();
              while ((line = rd.readLine()) != null) {
                  // Process line...
                  responseBuff.append(line);
              }
              response = responseBuff.toString();
              Log.d("response", response);
          }catch(Exception e){
              Log.d("buffer error", e.toString());
          }finally {
              if (is != null) {
                  try {
                      wr.close();
                      is.close();
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              } 
  </code></pre>