認証にSpring Securityを使用するアプリケーションがあります。j2ME midletからこのアプリケーションに接続しようとしています
そのため、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();
}
}