没有在HttpGet的标题中获取集合Cookie

时间:2014-07-03 11:49:27

标签: java android

我第一次登录时会收到“Set-Cookies”

Header Response:

07-03 17:10:46.191: I/System.out(19053): Key : Date ,Value : Thu, 03 Jul 2014 11:40:31 GMT
07-03 17:10:46.191: I/System.out(19053): Key : Server ,Value : Apache/2.2.22 (Debian)
07-03 17:10:46.191: I/System.out(19053): Key : X-Powered-By ,Value : PHP/5.4.4-14+deb7u9
07-03 17:10:46.191: I/System.out(19053): Key : Set-Cookie ,Value : PHPSESSID=0hecusmh1a5qn90s71moohtf71; path=/
07-03 17:10:46.191: I/System.out(19053): Key : Expires ,Value : Thu, 19 Nov 1981 08:52:00 GMT
07-03 17:10:46.191: I/System.out(19053): Key : Cache-Control ,Value : no-store, no-cache, must-revalidate, post-check=0, pre-check=0
07-03 17:10:46.191: I/System.out(19053): Key : Pragma ,Value : no-cache
07-03 17:10:46.191: I/System.out(19053): Key : Vary ,Value : Accept-Encoding
07-03 17:10:46.191: I/System.out(19053): Key : Content-Length ,Value : 0
07-03 17:10:46.191: I/System.out(19053): Key : Keep-Alive ,Value : timeout=5, max=100
07-03 17:10:46.191: I/System.out(19053): Key : Connection ,Value : Keep-Alive
07-03 17:10:46.191: I/System.out(19053): Key : Content-Type ,Value : text/html
07-03 17:10:46.191: I/System.out(19053): Get Response Header By Key ...
07-03 17:10:46.191: I/System.out(19053): Server - Apache/2.2.22 (Debian)
07-03 17:10:46.191: I/System.out(19053):  Done







When I get logout and try to login again i did not receive any "Set-Cookies" in the header

07-03 17:00:58.731: I/System.out(12989): Key : Date ,Value : Thu, 03 Jul 2014 11:30:44 GMT
07-03 17:00:58.731: I/System.out(12989): Key : Server ,Value : Apache/2.2.22 (Debian)
07-03 17:00:58.731: I/System.out(12989): Key : X-Powered-By ,Value : PHP/5.4.4-14+deb7u9
07-03 17:00:58.731: I/System.out(12989): Key : Expires ,Value : Thu, 19 Nov 1981 08:52:00 GMT
07-03 17:00:58.731: I/System.out(12989): Key : Cache-Control ,Value : no-store, no-cache, must-revalidate, post-check=0, pre-check=0
07-03 17:00:58.731: I/System.out(12989): Key : Pragma ,Value : no-cache
07-03 17:00:58.731: I/System.out(12989): Key : Vary ,Value : Accept-Encoding
07-03 17:00:58.731: I/System.out(12989): Key : Content-Length ,Value : 0
07-03 17:00:58.731: I/System.out(12989): Key : Keep-Alive ,Value : timeout=5, max=96
07-03 17:00:58.731: I/System.out(12989): Key : Connection ,Value : Keep-Alive
07-03 17:00:58.731: I/System.out(12989): Key : Content-Type ,Value : text/html
07-03 17:00:58.731: I/System.out(12989): Get Response Header By Key ...
07-03 17:00:58.731: I/System.out(12989): Server - Apache/2.2.22 (Debian)
07-03 17:00:58.741: I/System.out(12989):  Done







Following is my code:
Links
1)session_url="https://www.hrccmajoritymaker.com/providers/index.php";  
2)list_assignments_url="https://www.hrccmajoritymaker.com/consumers/secure_walklist_consumer.php?tok="+MainActivity.request_token+"&act=list_assignments&walklist=";
3)Login_url="https://www.hrccmajoritymaker.com/consumers/auth_consumer.php";    








 String basicAuth = "Basic " + Base64.encodeToString((email.getText().toString().trim()+":"+password.getText().toString().trim()).getBytes(), Base64.NO_WRAP);              


                try {
                    HttpGet httpGet = new HttpGet(CommonUtilities.session_url);

                    httpGet.addHeader("Authorization", basicAuth);
                    httpResponse = MainActivity.client.execute(httpGet);

// httpResponse = MainActivity.client.execute(httpGet,localContext);                         httpEntity = httpResponse.getEntity();                         jsonstr = EntityUtils.toString(httpEntity);                         int statusCode = httpResponse.getStatusLine()。getStatusCode();                          httpResponse.getAllHeaders()的toString();

                            Log.v("statusCode", "statusCode"+statusCode);
                            Log.v("httpResponse", "httpResponse="+httpResponse);
                            Log.v("httpEntity", "httpEntity="+httpEntity);
                            Log.v("httpEntity", "httpEntity ss="+ httpResponse.getAllHeaders().toString());
                            Header[] headers = httpResponse.getAllHeaders();




                            for (Header header : headers) {
                                System.out.println("Key : " + header.getName() 
                                                   + " ,Value : " + header.getValue());


                            }

                            System.out.println("\nGet Response Header By Key ...\n");
                            String server = httpResponse.getFirstHeader("Server").getValue();

                            if (server == null) {
                                System.out.println("Key 'Server' is not found!");
                            } else {
                                System.out.println("Server - " + server);
                            }

                            System.out.println("\n Done");


                            Log.d("value", "value="+value);

                            // MD5 STRING 
                            request_token= md5(CommonUtilities.secret_key+CommonUtilities.consumer_key+sessionid);

                            Log.v("request_token", "request_token="+request_token);

// request_token = md5(CommonUtilities.secret_key + CommonUtilities.consumer_key + sessionid);

                            //fetching first 10 characters of the string and contacting with consumer key 
                            request_token = request_token.substring(0, 10)+CommonUtilities.consumer_key;

                            Log.v("upToNCharacters", "upToNCharacters="+request_token);





  jsonstr=sh.makeServiceCall(CommonUtilities.list_assignments_url, ServiceHandler.GET);
                    Log.v("jsonstrREsult", "jsonstr="+jsonstr);

                     if(jsonstr.contains("login.php")){
                         String[] split=jsonstr.split("=");
                          oauth_token=split[1];

                          split = new String[0];
                          split=oauth_token.split("\"");

                          oauth_token=split[0];
                         Log.v("oauth_token", "oauth_token="+oauth_token);

                     }

                     else{
                         Log.v("else", "elseee");
                     }


                     List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                     nameValuePairs.add(new BasicNameValuePair("act","authenticate"));
                        nameValuePairs.add(new BasicNameValuePair("tok",request_token));
                        nameValuePairs.add(new BasicNameValuePair("alias",email.getText().toString())); 
                        nameValuePairs.add(new BasicNameValuePair("password",password.getText().toString()));
                        nameValuePairs.add(new BasicNameValuePair("oauth_token",oauth_token));


                        Log.v("Link", "Link="+CommonUtilities.Login_url);
                        Log.v("nameValuePairs", "nameValuePairs="+nameValuePairs);



                        jsonstr=sh.makeServiceCall(CommonUtilities.Login_url, ServiceHandler.POST, nameValuePairs); 

                        Log.v("jsonstr", "jsonstr="+jsonstr);



                        if (jsonstr != null) {
                            try {
                                JSONObject jsonObj = new JSONObject(jsonstr);

                              Log.v("jsonObj", "jsonObj"+jsonObj);
                                int err=jsonObj.getInt("err");



                                Log.v("err", "err="+err);


                                obj  = jsonObj.getString("obj");



                                Log.v("obj", "obj="+obj);






                            } 
                            catch (JSONException e) {
                                e.printStackTrace();
                            }
                        } 

                        else {
                            Log.e("ServiceHandler", "Couldn't get any data from the url");
                        }   

0 个答案:

没有答案