简体   繁体   English

使用loopj时出错:“找不到用于认证路径的信任锚。”

[英]Error when using loopj: “Trust anchor for certification path not found.”`

Currently I am working on a project, on which I need to GET/PUT data from a web server with basic authentication on Android. 目前,我正在一个项目上,我需要使用Android上的基本身份验证从Web服务器GET/PUT数据。

I followed the instructions of http://loopj.com/android-async-http/ but I encountered 我遵循了http://loopj.com/android-async-http/的说明,但是遇到了

"Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found."` “由以下原因引起:java.security.cert.CertificateException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚。”

The method on the website above is to make use of HttpClient which is deprecated now. 上面网站上的方法是利用现在不推荐使用的HttpClient I know there is HttpURLConnection , but I cannot find a suitable tutorial for my purpose. 我知道有HttpURLConnection ,但是找不到适合我目的的教程。

Answer here: Http Basic Authentication in Java using HttpClient? 在这里回答: Java中使用HttpClient的Http基本身份验证?

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;


public class HttpBasicAuth {

    public static void main(String[] args) {

        try {
            URL url = new URL ("http://ip:port/login");
            String encoding = Base64Encoder.encode ("test1:test1");

            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setDoOutput(true);
            connection.setRequestProperty  ("Authorization", "Basic " + encoding);
            InputStream content = (InputStream)connection.getInputStream();
            BufferedReader in   = 
                new BufferedReader (new InputStreamReader (content));
            String line;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
        } catch(Exception e) {
            e.printStackTrace();
        }

    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “未找到证书路径的信任锚”的问题。 - Problem with “Trust anchor for certification path not found.” java.security.cert.CertPathValidatorException:未找到证书路径的信任锚。 安卓 2.3 - java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. Android 2.3 CertPathValidatorException:未找到证书路径的信任锚。 在 android 中更新 gradle 和 gradle 插件后 - CertPathValidatorException: Trust anchor for certification path not found. in android after update gradle and gradle plugin Android:CertPathValidatorException:找不到证书路径的信任锚 - Android: CertPathValidatorException: Trust anchor for certification path not found Android 7:找不到认证路径的信任锚 - Android 7: Trust anchor for certification path not found Smack:“找不到证书路径的信任锚” - Smack: “Trust anchor for certification path not found” 在OkHttp中将证书信任/列入白名单(找不到证书路径的信任锚) - Trust/whitelist a certificate in OkHttp (Trust anchor for certification path not found) Hostgator 启用的免费 SSL - Android 错误:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚 - Free SSL Enabled by Hostgator - Android Error : java.security.cert.CertPathValidatorException: Trust anchor for certification path not found SSLHandshakeException 未找到证书路径的信任锚 Android HTTPS - SSLHandshakeException Trust anchor for certification path not found Android HTTPS javax.net.ssl.SSLHandshakeException:找不到证书路径的信任锚 - javax.net.ssl.SSLHandshakeException: Trust anchor for certification path not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM