public static string GetRequest1 (string URL, defaulthttpclient client, String CharSet) throws Exception { String result = null; int statusCode = 0; HttpGet GetMethod = new HttpGet (URL); LOG.D (TAG, "do the getrequest,url=" + URL + ""); try { Getmethod.setheader ("User-agent", user_agent); Getmethod.setheader ("Cookie", "cy=" + value);//This is dedicated to the public comment on the incoming Cookie parameter for the purpose of obtaining the city information selected by the user Add User password Authentication information Client.getcredentialsprovider (). SetCredentials ( New Authscope (NULL,-1), New Usernamepasswordcredentials (Musername, Mpassword)); HttpResponse HttpResponse = Client.execute (GetMethod); StatusCode = 200 Normal StatusCode = Httpresponse.getstatusline (). Getstatuscode (); LOG.D (TAG, "statuscode =" + statuscode); Processing the returned HttpResponse information if (StatusCode = = 200) { result = Retrieveinputstream (Httpresponse.getentity (), CharSet); Cookie Cookie; String Cookname,cookvalue; list<cookie> cookies = Client.getcookiestore (). GetCookies (); if (Cookies.isempty ()) { LOG.I (TAG, "-------Cookie NONE---------"); } else { for (int i = 0; i < cookies.size (); i++) { Save cookies Cookie = Cookies.get (i); Cookname = Cookie.getname (). Trim (); Cookvalue = Cookie.getvalue (). Trim (); if (Cookname.equals ("Cy")) { name = Cookname; value = Cookvalue; } } } } else result = "Networkerror"; catch (Connecttimeoutexception e) {//timeout or network connection error result = "Timeouterror"; E.printstacktrace (); catch (Clientprotocolexception e) { result = "Networkerror"; E.printstacktrace (); catch (Exception e) { result = "Readerror"; LOG.E (TAG, E.getmessage ()); throw new Exception (e); finally { Getmethod.abort (); } return result; } |