Problem in httpurlconnection immer status 500

Ich versuche, das login-url und ich bekomme den status code 500 in httpurlconnevtion

public static String excutePost(String targetURL, String urlParameters)
  {
    URL url;
    HttpURLConnection connection = null;  
    try {
      //Create connection
      url = new URL(targetURL);
      connection = (HttpURLConnection)url.openConnection();
      connection.setRequestMethod("POST");
      connection.setRequestProperty("Content-Type", 
           "application/x-www-form-urlencoded");
      connection.setRequestProperty("Connection", "Keep-Alive");    
      connection.setRequestProperty("Content-Length", "" + 
               Integer.toString(urlParameters.getBytes().length));
      connection.setRequestProperty("Content-Language", "en-US");  
      connection.setRequestProperty("Accept-Encoding", ""); 
      connection.setUseCaches (false);
      connection.setDoInput(true);
      connection.setDoOutput(true);

      //Send request
      DataOutputStream wr = new DataOutputStream (
                  connection.getOutputStream ());
      wr.writeBytes (urlParameters);
      wr.flush ();
      wr.close ();

      System.out.println("status :"+connection.getResponseCode());
      System.out.println("getErrorStream() :"+connection.getErrorStream());
      //Get Response    
      InputStream is = connection.getInputStream();
      BufferedReader rd = new BufferedReader(new InputStreamReader(is));
      String line;
      StringBuffer response = new StringBuffer(); 
      while((line = rd.readLine()) != null) {
        response.append(line);
        response.append('\r');
      }
      rd.close();
      return response.toString();

    } catch (Exception e) {

      e.printStackTrace();
      return null;

    } finally {

      if(connection != null) {
        connection.disconnect(); 
      }
    }
  }

und mein params sind

String urlParameters =
                        "pwd1=" + URLEncoder.encode("DEMO123", "UTF-8") +
                        "&badge=" + URLEncoder.encode("1233", "UTF-8");

ich bin immer logcat

status :500
getErrorStream() :libcore.net.http.FixedLengthInputStream@417bc5c0

danke

**EDITED 2**

Ich versuche auch mit

DataOutputStream dos = new DataOutputStream(connection.getOutputStream());

        //Add badge
        dos.writeBytes(LINE_START + BOUNDRY + LINE_END);
        dos.writeBytes("Content-Disposition: form-data; name='badge';");
        dos.writeBytes(LINE_END + LINE_END);
        dos.writeBytes("1233");
        dos.writeBytes(LINE_END);

        //Add password
        dos.writeBytes(LINE_START + BOUNDRY + LINE_END);
        dos.writeBytes("Content-Disposition: form-data; name='pwd1';");
        dos.writeBytes(LINE_END + LINE_END);
        dos.writeBytes("DEMO123");
        dos.writeBytes(LINE_END);

InformationsquelleAutor Android | 2013-03-12

Schreibe einen Kommentar