如何在android中进行http认证

发布于 2024-12-05 16:45:09 字数 1206 浏览 0 评论 0原文

我正在使用以下代码

 public void executeHttpGet() throws Exception {
    dialog = new ProgressDialog(this);
    dialog.setCancelable(true);

    // set a message text
    dialog.setMessage("Loading...");

    // show it
    dialog.show();
     BufferedReader in = null;

            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet();
         String url=   "http://newdev.objectified.com/morris/interface/mobile.php?method=dealerLogin&username=alixxxxxxxx&password=jamali";


            request.setURI(new URI(url));
            HttpResponse response = client.execute(request);
            in = new BufferedReader
            (new InputStreamReader(response.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 page = sb.toString();
            Toast.makeText(this, page, Toast.LENGTH_LONG).show();
         //  dialog.dismiss();


    }

现在我想对此进行http身份验证,请帮忙吗?

I am using following code

 public void executeHttpGet() throws Exception {
    dialog = new ProgressDialog(this);
    dialog.setCancelable(true);

    // set a message text
    dialog.setMessage("Loading...");

    // show it
    dialog.show();
     BufferedReader in = null;

            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet();
         String url=   "http://newdev.objectified.com/morris/interface/mobile.php?method=dealerLogin&username=alixxxxxxxx&password=jamali";


            request.setURI(new URI(url));
            HttpResponse response = client.execute(request);
            in = new BufferedReader
            (new InputStreamReader(response.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 page = sb.toString();
            Toast.makeText(this, page, Toast.LENGTH_LONG).show();
         //  dialog.dismiss();


    }

Now I want to do http authentication on this ,please help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏日落 2024-12-12 16:45:09

它应该看起来像这样:

     HttpClient client = new DefaultHttpClient();
     HttpGet request = new HttpGet();
     String url=   "http://newdev.objectified.com/morris/interface/mobile.php?method=dealerLogin&username=alixxxxxxxx&password=jamali";

     String login = "alixxxxxxxx";
     String pass = "jamali";

     client.getCredentialsProvider().setCredentials(new AuthScope("newdev.objectified.com", 80), new UsernamePasswordCredentials(login, pass));

     request.setURI(new URI(url));
     HttpResponse response = client.execute(request);

It should look like this:

     HttpClient client = new DefaultHttpClient();
     HttpGet request = new HttpGet();
     String url=   "http://newdev.objectified.com/morris/interface/mobile.php?method=dealerLogin&username=alixxxxxxxx&password=jamali";

     String login = "alixxxxxxxx";
     String pass = "jamali";

     client.getCredentialsProvider().setCredentials(new AuthScope("newdev.objectified.com", 80), new UsernamePasswordCredentials(login, pass));

     request.setURI(new URI(url));
     HttpResponse response = client.execute(request);
有木有妳兜一样 2024-12-12 16:45:09

对于 http 身份验证, Authenticator 类是您的朋友。

For http authentication the Authenticator class is your friend.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文