title: blackberry HttpConnection.GET
body: <p>URL: <a href="http://monSite/GET.asp" rel="nofollow">http://monSite/GET.asp</a></p>
  
  <p>we must authenticate before getting the result.</p>
  
  <p>I want to send the login and password with <code>HttpConn.setRequestMethod (HttpConnection.POST)</code>  and retrieve the XML file with <code>HttpConn.setRequestMethod (HttpConnection.GET)</code> with the same HTTP Client.</p>
  
  <pre><code>conn = (HttpConnection) new ConnectionFactory().getConnection(_url).getConnection();
  URLEncodedPostData postData = null;
  postData = new URLEncodedPostData("UTF-8", false);
  
  postData.append("userName",_username);
  postData.append("passWord", _password);
  
  
  conn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LANGUAGE, "en-US");
  
  conn.setRequestProperty(HttpProtocolConstants.HEADER_CACHE_CONTROL,"no-cache, no-store, no-transform");
  
  
  // Specify the content type.
  conn.setRequestMethod(HttpConnection.POST);
  conn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE, postData.getContentType());
  
  byte [] postBytes = postData.getBytes();
  conn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH, Integer.toString(postBytes.length));
  os = conn.openOutputStream();
  
  os.write(postBytes);
  
  os.flush();
  os.close();
  //GET XML file
  conn.setRequestMethod(HttpConnection.GET);
  conn.setRequestProperty("User-Agent",
          "Profile/MIDP-1.0 Confirguration/CLDC-1.0");
  
  if (conn.getResponseCode() == HttpConnection.HTTP_OK) {
  int total = 0;
  int size = 1024;
  char[] buffer = new char[size];
  int len;
  
  InputStreamReader isr = new InputStreamReader(conn.openInputStream(), "UTF-8");
  
  while ((len = isr.read(buffer, 0, size)) &gt; 0)
  {
      buff.append(buffer, 0, len);
      total += len;
  }
  
  
  
  result = buff.toString();
  } else {
      result = "Error in connection" + conn.getResponseCode();
  }
  
  
  } catch (Exception ex) {
      ex.printStackTrace();
  } finally {
      try {
          if (in != null) {
              in.close();
          }
          conn.close();
  
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>the HttpConnection.POST works very well but GET no (login failed: the authentication parameter does not saved)</p>