解决Target host must not be null, or set in parameters.

以下是在get方式中遇到,把每个参数采用utf-8编码即可

	
//        这样写是错误的,后面不能一次整体编码
//        sb.append("http://abc.com/api?")
//                append("body=").append(body).append("&ids=").append(JSONArray.toJSONString(ids));
//        resultInfo = this.callNotice(URLEncoder.encode(sb.toString(),"utf-8");

//        get方式要每个属性编码一次,不然报错java.lang.IllegalStateException: Target host must not be null, or set in parameters.
        try {
            sb.append("http://abc.com/api?") 
                    .append("&body=").append(URLEncoder.encode(body, "utf-8"))
                    .append("&ids=").append(URLEncoder.encode(JSONArray.toJSONString(ids), "utf-8"))
            resultInfo = this.callNotice(sb.toString());
			...................









你可能感兴趣的:(Java)