小编Đặn*_*ang的帖子

无法从标头响应中获取Cookie

我是初学者,我在这段代码中提出了一个HTTP请求并得到了回复:

 public void postData() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://192.168.1.105/moodle/login/index.php"); //http://192.168.1.105/moodle/login/index.php

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("username", "admin"));
        nameValuePairs.add(new BasicNameValuePair("password", "dtkTj29000g!"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        httppost.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        String responseContent = EntityUtils.toString(response.getEntity());
        Log.i("Response", responseContent );


        Header[] header=response.getAllHeaders();
        for(int i=0;i<header.length;i++){
            String a=header[i].getValue();
            String b=header[i].getName();
            Log.i("quangggggggggggggg",b+"__________"+a);
        }

        WebView webview = (WebView)findViewById(R.id.webkit1);
        webview.loadDataWithBaseURL(null,responseContent, "text/html", "utf-8",null);



    /*    cookies = …
Run Code Online (Sandbox Code Playgroud)

cookies android

1
推荐指数
1
解决办法
6056
查看次数

标签 统计

android ×1

cookies ×1