【发布时间】:2016-05-25 06:05:17
【问题描述】:
我正在尝试获取从网站发送的识别 cookie,为此我使用Volley library。
首先,是的,在过去的几天里,我已经广泛搜索了这个主题,并使用了我设法收集到这段代码的所有答案:
public class Login extends AppCompatActivity {
StringRequest stringRequest = null;
RequestQueue queue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
queue = Volley.newRequestQueue(this);
Button b = (Button) findViewById(R.id.bauth);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String url = "http://daviddurand.info/D228/pizza/?action=login&user=david";
stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
CookieManager manager = new CookieManager();
CookieHandler.setDefault(manager);
try {
Log.d("URI 1", manager.getCookieStore().get(new URI("http://daviddurand.info/D228/pizza/?action=login&user=david")).toString());
} catch (URISyntaxException e) {
e.printStackTrace();
}
Log.d("URIS", manager.getCookieStore().getURIs().toString());
Log.d("COOKIE", manager.getCookieStore().getCookies().toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//error
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
}
});
}
}
它只返回空括号,所以我猜错了.. 首先,我在这里走对路了吗?以及我需要添加什么才能使其正常工作?
【问题讨论】:
-
哎呀。我认为您必须创建一个自定义的
Request子类,该子类将返回服务器数据和cookie。我不相信CookieManager在我请求它们的确切时间拥有更新的 cookie。
标签: android cookies android-volley