title: HttpURLConnection to send POST data gives error
body: <p>I'm using <a href="http://digitallibraryworld.com/?p=189" rel="nofollow">this</a> script to try to send POST data to a PHP script from my Android app. But it doesn't even let me Run it due to the error "loginUrl cannot be resolved". Since other people seem to have got this code working, have I missed something obvious here? Here's the code but changed by me (see it with comments by the link above):</p>
  
  <pre><code>    public void postData() {
      URL url;
      HttpURLConnection conn;
  
      try{
      url=new URL("http://mysite/test.php");
  
      String param="param1=" + URLEncoder.encode("value1","UTF-8")+
      "&amp;param2="+URLEncoder.encode("value2","UTF-8")+
      "&amp;param3="+URLEncoder.encode("value3","UTF-8");
  
      conn=(HttpURLConnection)loginUrl.openConnection();
      conn.setDoOutput(true);
      conn.setRequestMethod("POST");
  
      conn.setFixedLengthStreamingMode(param.getBytes().length);
      conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
      PrintWriter out = new PrintWriter(conn.getOutputStream());
      out.print(param);
      out.close();
  
      String response= "";
  
      Scanner inStream = new Scanner(conn.getInputStream());
  
      while(inStream.hasNextLine())
      response+=(inStream.nextLine());
  
      }
      catch(MalformedURLException ex){  
      Toast.makeText(GameButton.this, ex.toString(), 1 ).show();
  
      }
      catch(IOException ex){
  
      Toast.makeText(GameButton.this, ex.toString(), 1 ).show();
      }
  } 
  </code></pre>
  
  <p>Thanks!</p>