reason:
Special characters are involved in the address, such as '|', '&', etc. So you can't directly use String insteadURI to access. The %0xXX method must be used to replace special characters. But this approach is not intuitive. So we can only convert the String into a URL first, and then use the method of generating a URI from the URL to solve the problem.
Solution:
使用 String encoderString = URLEncoder.encode(testString, "utf-8");
public class demo {
public static void main(String[] args) {
String testString = "CTMSEventDTL TimeOut.Merge msg";
try {
//发送方报错后用这个转一下
String encoderString = URLEncoder.encode(testString, "utf-8");
System.out.println(encoderString);//CTMSEventDTL+TimeOut.Merge+msg
//接收方再转回去
String decodedString = URLDecoder.decode(encoderString, "utf-8");
System.out.println(decodedString);//CTMSEventDTL TimeOut.Merge msg
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}