Post 到spring security的j2me连接

Post 到spring security的j2me连接,post,java-me,spring-security,Post,Java Me,Spring Security,我有一个使用spring安全性进行身份验证的应用程序 我正在尝试从j2ME midlet连接到此应用程序 因此,我使用post方法从j2me应用程序发送HTTP请求来发送用户名和密码,但它不起作用 PostMethode代码很好。它与同一应用程序的其他服务一起工作(不需要身份验证) 但是当涉及到身份验证时,我得到的响应代码是302 这是我的密码 OutputStream os = null; HttpConnection connection = null;

我有一个使用spring安全性进行身份验证的应用程序 我正在尝试从j2ME midlet连接到此应用程序

因此,我使用post方法从j2me应用程序发送HTTP请求来发送用户名和密码,但它不起作用

PostMethode代码很好。它与同一应用程序的其他服务一起工作(不需要身份验证)

但是当涉及到身份验证时,我得到的响应代码是302

这是我的密码

        OutputStream os = null;
        HttpConnection connection = null;
        InputStream is = null;
        StringBuffer sb = new StringBuffer();
        try {
                connection = (HttpConnection)Connector.open("http://localhost:8080/myAppli/j_spring_security_check");
                connection.setRequestMethod(HttpConnection.POST);
                connection.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.1");
                connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

                os = connection.openOutputStream();
                byte data[] =("j_username=appliusername&j_password=applipassword").getBytes();
                os.write(data);
                os.flush();
                int respCode=connection.getResponseCode();

           if (connection.getResponseCode() == HttpConnection.HTTP_OK) {
                is = connection.openInputStream();
                if (is != null ) {
                    int ch = -1;
                    while ((ch = is.read()) != -1) {

                    sb.append((char)ch);
                     }

               }
          }else {
              System.out.println("Error in opening HTTP Connection. Error#" + respCode);
           }              
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
             try {
                    if (is != null) {
                        is.close();
                        //is = null;
                    }
                     if (os != null) {
                        os.close();
                        //is = null;
                    }
                    if (connection != null) {
                        connection.close();
                       // connection = null;
                    }
              }catch (Exception e2) {
                    e2.printStackTrace();
            }
        }

您可以尝试使用URL的授权部分,并从

"http://localhost:8080/myAppli/j_spring_security_check"  


有关这方面的更多信息,请查看

I get java.lang.IllegalArgumentException:无效的端口格式applipassword@localhost:8080作为端口,请在真实设备上试用。此代码是否适用于简单的Post服务?例如,一个带有doPost方法的Servlet会获得j_用户名和j_密码参数吗?我还没有这样做,但是我会怎么做呢
"http://appliusername:applipassword@localhost:8080/myAppli/j_spring_security_check"