HTTP错误:java.lang.IllegalArgumentException: Illegal character in scheme at index 0: ?http://xxxxxx

读取T卡文件里的域名,HTTP请求出现如下错误

java.lang.IllegalArgumentException: Illegal character in scheme at index 0: http://xxxxxxxxxxx
at java.net.URI.create(URI.java:727)
at org.apache.http.client.methods.HttpPost.<init>(HttpPost.java:84)

......

出现该错误时,读取域名的代码如下

protected String getFileContent(File file) {
        String content  = "";
        if (file.isDirectory() ) {    //检查此路径名的文件是否是一个目录(文件夹)
            Log.i("zeng", "The File doesn‘t not exist "
                +file.getName().toString()+file.getPath().toString());
        } else {
            if (file.getName().endsWith(".txt")) {//文件格式为txt文件
                try {
                    InputStream instream = new FileInputStream(file);
                    if (instream != null) {
                        InputStreamReader inputreader
                            =new InputStreamReader(instream, "UTF-8");
                        BufferedReader buffreader = new BufferedReader(inputreader);
                        String line="";
                        //分行读取
                       while (( line = buffreader.readLine()) != null) {
                            content += line + "\n";
                        }
                        instream.close();        //关闭输入流
                    }
                }
                catch (java.io.FileNotFoundException e) {
                    Log.d("TestFile", "The File doesn‘t not exist.");
                }
                catch (IOException e)  {
                     Log.d("TestFile", e.getMessage());
                }
            }
        }
        return content ;
    }

修改为如下方法后,HTTP请求正常

private static String getFileContent(File file) {
        String content = "";
        try {
            FileInputStream fin = new FileInputStream(file);
            int length;
            length = fin.available();
            byte [] buffer = new byte[length];
            fin.read(buffer);
            content = EncodingUtils.getString(buffer, "UTF-8");
            fin.close();
            return content;
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return content;
    }

原文地址:https://www.cnblogs.com/suxiaoqi/p/9762005.html

时间: 2024-11-09 01:48:58

HTTP错误:java.lang.IllegalArgumentException: Illegal character in scheme at index 0: ?http://xxxxxx的相关文章

java.lang.IllegalArgumentException: Illegal character in query at index 261

在BaseFragment中使用了LoadingPage,而LoadingPage的联网加载使用的是AsyncHttpClient.一直报java.lang.IllegalArgumentException: Illegal character in query at index 261解析不成功,改成OkHttp解析即可. 网上有些方法,说先URLEncode再拼接,如果解决不了,换个联网请求方式,试一下.

HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalArgumentException: Control character in cookie value or attribute.

1 HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalArgumentException: Control character in cookie value or attribute. 2 type Exception report 3 4 message Request processing failed; nested exception is java.lang.Illega

cookie遇到java.lang.IllegalArgumentException: Control character in cookie value or attribute

java.lang.IllegalArgumentException: Control character in cookie value or attribute. 该异常说明cookie中的value或属性有控制字符,但是我设置的value并没有特殊字符.初步怀疑是中文编码问题,于是在将字符串进行base64编码之前先用Cookie cookie = new Cookie("name", URLEncoder.encode(str, "UTF-8"));将原字符

【异常】Exception in thread &quot;main&quot; java.lang.IllegalArgumentException: Illegal pattern c

在windows上执行的时候,option(“timestampFormat”, “yyyy/MM/dd HH:mm:ss ZZ”)必须带上,不然报错: Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern component: XX. 使用比如:val df1 = spark.read.format("json").option("timestampF

解决多指操作放大缩小 指针错误 java.lang.IllegalArgumentException: pointerIndex out of range

/** Custom your own ViewPager to extends support ViewPager. java source: */ /** Created by azi on 2013-6-21. */ package com.chaokuadi.android.support.view; import android.content.Context; import android.util.AttributeSet; import android.view.MotionEv

创建Cookie抛出异常:java.lang.IllegalArgumentException: Control character in cookie value

调用Cookie对象的构造函数可以创建Cookie.Cookie对象的构造函数有两个字符串参数:Cookie名字和Cookie值.   名字和值都不能包含空白字符以及下列字符:[ ] ( ) < > = , " / ? @ : ; 错误出在response.addCookie(cookie)://cookie 是一个Cookie实例. J2EE Doc里面的,cookies只支持ASCII字符,而且不能有逗号,分号,空白.或者以$开头.名字在创建后不能改变.如果要存储中文的,先用UR

java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

微信小程序前后台使用get方式传参时报错如图.但在微信开发平台和苹果测试都没事,在安卓手机上就报这个错,猜想原因是get传递了汉字的原因. 尝试了下在后台输出从前台获取的参数,但是后台什么也没有获取到,直接报错. 最后用id替换了url里的中文:因为搜索功能不能替换中文的,改成了post请求. 参考:[Java EE]get和post请求的编码过程get请求中文参数乱码的解决之道 网上也有很多报这个错的原因是含有特殊字符:有些版本的Tomcat严格按照 RFC 3986规范进行访问解析,而 RF

Glide错误java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity

解决办法 在使用Glide的那段代码加是否在主线程判断 if(Util.isOnMainThread()) { Glide.with(ClassifyItemDetailActivity.this).load(ConstantsYiBaiSong.CLASSIFY_LIST_ITEM_DETAIL_IMAGE + lists.get(i).get( "face")) .diskCacheStrategy(DiskCacheStrategy.ALL).into(imageView); }

java.lang.IllegalArgumentException: Invalid character found in the request target.

http参数存在特殊字符: 特殊字符是出现在后面跟的参数中,对参数进行 URL 编码,可以使用 JavaScript 中的 encodeURIComponent() 函数. 原文地址:https://www.cnblogs.com/YuyuanNo1/p/9717274.html