2012-10-16 44 views
1

我有使用彈簧安全認證 我米試圖連接到從J2ME midlet的本申請J2ME連接到彈簧安全

所以我使用POST方法來發送從一個J2ME應用程序的HTTP請求的應用程序發送用戶名和密碼,但它不起作用

後處理代碼很好。它使用相同的應用程序(不要求認證)

,但是當涉及到認證我得到響應碼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(); 
      } 
     } 

回答

0

你可以嘗試使用URL和變化的授權部分從

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

"http://appliusername:[email protected]:8080/myAppli/j_spring_security_check" 

有關更多信息,請看一看http://en.wikipedia.org/wiki/URI_scheme#Examples

+0

我得到java.lang.IllegalArgumentException異常:無效端口格式 – user1662513

+0

現在看來,這需要applipassword @本地:8080 – user1662513

+0

您是否嘗試過此上的端口設備或只是在模擬器? –