当用户使用账号密码登录成功将从服务器获得一个 sessionid, 该 sessionid 也会保存在服务器上,接下来的每一次请求都会验证这个 sessionid。我的问题是怎么通过 HttpPost 的方式获得一个 sessionid,我更想知道后台服务器是怎么做到的。下面是 client 端的代码:HttpClient httpclient = new DefaultHttpClient();String url = "http://localhost:8080/login.jsp";HttpPost httppost = new HttpPost(url);try { // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("account", "root")); nameValuePairs.add(new BasicNameValuePair("password", "ilovepassword")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); /* get a sessionid from response simple code * / string content = response.getEntity().getContent().toString(); * / org.json.JSONObject respMessage = new JSONObject(content); * / sessionid = (String)respMessage.get("sessionid"); * / */} catch (ClientProtocolException e) { // TODO Auto-generated catch block} catch (IOException e) { // TODO Auto-generated catch block}我的问题具体地说,就是当我的 url 设置不是一个页面的时候,webservice 的 server 端是怎么处理 httpclient 传输过来的 account 和 password 的,然后怎么返回 sessionid 的。谢谢!附一个外国人的提问链接:http://www.coderanch.com/t/507200/Web-Services/java/web-service-login-operation-return
添加回答
举报
0/150
提交
取消