當用戶使用賬號密碼登錄成功將從服務器獲得一個 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
提交
取消