【发布时间】:2017-03-18 06:58:05
【问题描述】:
我正在开发一个带有 NodeJS 后端服务器的 Android 应用程序。当用户登录后向不同页面发出请求时,我在验证用户时遇到问题。
登录后,我将set-cookie 值存储在SharedPrefs 中。现在,当我发出 POST 请求时,我在标头中发送 set-cookie 值,即 con.setRequestProperty("set-cookie", cookie); 用于使用 req.user.authenticate 在后端验证用户。
但是,req.user 未定义,因此请求失败。这里有什么问题?谢谢。
下面是我的 POST 请求代码。
con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", "\"Mozilla/5.0\"");
con.setDoOutput(true);
JSONObject jsonParam = new JSONObject();
try {
jsonObject.accumulate("set-cookie", cookie);
} catch (JSONException e) {
e.printStackTrace();
}
OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());
out.write(jsonParam.toString());
out.close();
int responseCode = con.getResponseCode();
System.out.println("Response Code:"+responseCode);
【问题讨论】:
标签: android node.js http-post session-cookies