我正在设置 cookie,然后发出 HTTP GET 请求,但没有得到任何响应。你能帮忙吗?由于某些原因,我没有输入确切的 URL。我的代码是:
DefaultHttpClient httpclient2 = new DefaultHttpClient();
CookieStore cookieStore = (CookieStore) new BasicCookieStore();
if(cookieStore != null){
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
httpclient2.setCookieStore(cookieStore);
HttpGet httpget = new HttpGet("URL");
try {
HttpResponse protectedappresource = httpclient2.execute(httpget,httpContext);
List<Cookie> cookies = cookieStore.getCookies();
Log.i("Cookie Store","Cookies size= " + cookies.size());
for (int i = 0; i < cookies.size(); i++) {
Cookie cookie1 = cookies.get(i);
Log.i("Cookie Store",""+cookie1.getValue());
}
BufferedReader in = new BufferedReader(new InputStreamReader(protectedappresource.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String result = sb.toString();
response = result;
System.out.println(" resource response " + result);