0

我正在使用此代码,但它没有设置 cookie...

URL url = new URL("http://10.0.2.2/test2.php");
                HttpClient httpClient = new DefaultHttpClient();
                CookieStore cookieStore = new BasicCookieStore();
                Cookie cookie = new BasicClientCookie("xxt", "5a5b98563c4aabd675b81e4ba0fdf6cf");
                cookieStore.addCookie(cookie);

                Cookie cookie2 = new BasicClientCookie("XXT", "5a5b98563c4aabd675b81e4ba0fdf6cf");
                cookieStore.addCookie(cookie2);

                HttpContext localContext = new BasicHttpContext();
                localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

                HttpPost post = new HttpPost("http://10.0.2.2/test2.php");
                HttpResponse response = httpClient.execute(post, localContext);
                toReturn = EntityUtils.toString(response.getEntity());
                //InputStream is = conn.getInputStream();
                //toReturn = inputStreamToString(is).toString();
                Log.d("downloaded", toReturn);

我究竟做错了什么?

4

1 回答 1

0

我正在这样做:

    BasicClientCookie cookie = new BasicClientCookie("XXT", "5a5b98563c4aabd675b81e4ba0fdf6cf");
    cookie.setExpiryDate(new Date("Fri Dec 11 15:24:17 GMT+06:00 2015"));
    cookie.setDomain("10.0.2.2");
    cookie.setPath("/");
    cookie.setVersion(1);
    cookie.setComment("");
    cookie.setValue("5a5b98563c4aabd675b81e4ba0fdf6cf");
    cookieStore.addCookie(cookie);
于 2015-11-11T09:39:24.487 回答