Java 成功的php会话需要什么?

Java 成功的php会话需要什么?,java,php,session,java-me,Java,Php,Session,Java Me,我正在编写一个客户端j2me应用程序,它使用post方法连接到基于php的api。出于安全目的,应用程序和api应该在一个会话中进行交互,超时时间为30分钟。我的问题是,即使会话超时尚未完成,应用程序用户也必须继续登录。我的php代码很好,因为我已经在浏览器上进行了测试,效果很好;但是应用程序失败了,我不得不继续登录。我可能遗漏了什么吗?这些是我使用Java应用程序发送到服务器的头文件 String phonenumber = this.phonenumberTextbox.getString(

我正在编写一个客户端j2me应用程序,它使用post方法连接到基于php的api。出于安全目的,应用程序和api应该在一个会话中进行交互,超时时间为30分钟。我的问题是,即使会话超时尚未完成,应用程序用户也必须继续登录。我的php代码很好,因为我已经在浏览器上进行了测试,效果很好;但是应用程序失败了,我不得不继续登录。我可能遗漏了什么吗?这些是我使用Java应用程序发送到服务器的头文件

String phonenumber = this.phonenumberTextbox.getString();
String password = this.passwordTextBox.getString();
HttpConnection httpConn = null;
String url = "http://192.168.56.1/?action=login-user";
InputStream is;
OutputStream os;
is = null;
os = null;
String sReply = "";
boolean loggedIn = false;
try {
    // Open an HTTP Connection object
    httpConn = (HttpConnection) Connector.open(url);
    // Setup HTTP Request to POST
    httpConn.setRequestMethod(HttpConnection.POST);
    httpConn.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Confirguration/CLDC-1.0");
    httpConn.setRequestProperty("Accept_Language", "en-US");
    //Content-Type is must to pass parameters in POST Request
    httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
           os = httpConn.openOutputStream();
    String params;
    params = "phonenumber=" + phonenumber + "&password=" + password;
    os.write(params.getBytes());

    // Read Response from the Server
    StringBuffer sb = new StringBuffer();
    is = httpConn.openDataInputStream();
    int chr;
    while ((chr = is.read()) != -1) {
        sb.append((char) chr);
    }
    // Web Server just returns stuff         
    sReply = sb.toString();
} catch (IOException ex) {
    System.out.println("Cannot find server");
} finally {
    if (is != null) {
        try {
            is.close();
        } catch (IOException ex) {
        }
    }
    if (os != null) {
        try {
            os.close();
        } catch (IOException ex) {
        }
    }
    if (httpConn != null) {
        try {
            httpConn.close();
        } catch (IOException ex) {
        }
    }
}
// do something with sReply

现在PHP的默认做法**在处理会话时,如果PHP生成一个cookie供客户端存储。java客户机必须存储此cookie(默认情况下称为phpsessid,但任何称职的PHP程序员都会更改cookie名称),并在后续请求时将其显示在HTTP头中

我对Java中的HTTP支持不是很熟悉,但如果它像curl一样,它将包括设置和检索cookie的选项


**过去,在发出请求时,可以通过查询字符串(GET参数)传递会话令牌,但由于这非常不安全,并且泄露了潜在的敏感信息,因此不再使用它,甚至可能不再作为选项提供

我认为您缺少cookie(如果在php中使用session_start(),则需要PHPSESSID cookie)