Java HttpsURLConnection&x2B;Cloudflare API FileNotFoundException

Java HttpsURLConnection&x2B;Cloudflare API FileNotFoundException,java,android,https,filenotfoundexception,Java,Android,Https,Filenotfoundexception,我正在尝试为android创建一个应用程序,并尝试从CloudFlare仪表板读取我的统计数据。 奇怪的是,如果我的代码到达ins=con!=无效的con.getInputStream():null它将显示“FileNotFoundException”。 标题按其应有的方式设置。以下是CF API文档中的引用: 仪表板视图提供整个CloudFlare网络中给定区域和时间段的总计和timeseries数据。 GET/zones/:区域标识符/分析/仪表板 - 有些参数是可选的,我已经仔细检查了我的

我正在尝试为android创建一个应用程序,并尝试从CloudFlare仪表板读取我的统计数据。 奇怪的是,如果我的代码到达
ins=con!=无效的con.getInputStream():null它将显示“FileNotFoundException”。
标题按其应有的方式设置。以下是CF API文档中的引用:

仪表板视图提供整个CloudFlare网络中给定区域和时间段的总计和timeseries数据。 GET/zones/:区域标识符/分析/仪表板 -

有些参数是可选的,我已经仔细检查了我的数据,它在Postman中运行良好

我尝试使用http,但CF不允许

我的代码:

class JsonRequest extends AsyncTask<String, String, String> {
private String readStream(InputStream is) {
    try {
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
        int i = is.read();
        while (i != -1) {
            bo.write(i);
            i = is.read();
        }
        return bo.toString();
    } catch (IOException e) {
        return "";
    }
}

protected String doInBackground(String... params) {
    URL myurl = null;
    try {
        myurl = new URL(params[0]);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    HttpsURLConnection con = null;
    try {
        con = (HttpsURLConnection)myurl.openConnection();
        con.setRequestProperty("X-Auth-Email", "email");
        con.setRequestProperty("X-Auth-Key", "key");
        con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        con.setRequestProperty("User-Agent","Mozilla/5.0 ( compatible ) ");
        con.setRequestProperty("Accept","*/*");
        con.setDoOutput(false);
    } catch (IOException e) {
        e.printStackTrace();
    }
    InputStream ins = null;
    try {
        ins = con != null ? con.getInputStream() : null; // FileNotFoundException
    } catch (IOException e) {
        e.printStackTrace();
    }
    InputStreamReader isr = new InputStreamReader(ins);
    BufferedReader in = new BufferedReader(isr);
    try {
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return readStream(ins);
    }
}
类JsonRequest扩展了异步任务{
私有字符串读取流(InputStream为){
试一试{
ByteArrayOutputStream bo=新建ByteArrayOutputStream();
int i=is.read();
而(i!=-1){
bo.write(i);
i=is.read();
}
返回bo.toString();
}捕获(IOE异常){
返回“”;
}
}
受保护的字符串doInBackground(字符串…参数){
URL myurl=null;
试一试{
myurl=新URL(参数[0]);
}捕获(格式错误){
e、 printStackTrace();
}
HttpsURLConnection con=null;
试一试{
con=(HttpsURLConnection)myurl.openConnection();
con.setRequestProperty(“X-Auth-Email”、“电子邮件”);
con.setRequestProperty(“X-Auth-Key”、“Key”);
con.setRequestProperty(“内容类型”、“应用程序/x-www-form-urlencoded”);
con.setRequestProperty(“用户代理”、“Mozilla/5.0(兼容)”);
con.setRequestProperty(“接受”,“*/*”);
con.设置输出(假);
}捕获(IOE异常){
e、 printStackTrace();
}
InputStream ins=null;
试一试{
ins=con!=null?con.getInputStream():null;//FileNotFoundException
}捕获(IOE异常){
e、 printStackTrace();
}
InputStreamReader isr=新的InputStreamReader(ins);
BufferedReader in=新的BufferedReader(isr);
试一试{
in.close();
}捕获(IOE异常){
e、 printStackTrace();
}
返回读取流(ins);
}
}