record

IHS作为web server,因为上传Base64图片流,如果url过长报错:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>414 Request-URI Too Long</title>
</head>
<body>
<h1>Request-URI Too Long</h1>
<p>The requested URL's length exceeds the capacity limit for this server.</p>
</body>
</html>

修改Apache的httpd.conf配置文件中添加

LimitRequestLine 4000000
LimitRequestFieldSize 4000000

LimitRequestLine 4000000 //Limit the size of the HTTP request line that will be accepted from the client
客户端发送的HTTP请求行的最大字节数【默认 8190】,请求行包括HTTP方法、URL、协议版本等,因此LimitRequestLine指令能够限制URL的长度,服务器会需要这个值足够大以装载它所有的资源名,包括可能在GET请求中所传递的查询部分的所有信息
LimitRequestFieldSize 4000000 //Limits the size of the HTTP request header allowed from the client
限制客户端发送的请求头的字节数 【默认 8190】,
LimitRequestBody 4000000 //Restricts the total size of the HTTP request body sent from the client

http请求包含(请求行,请求头,请求体)

请求行:包含方法字段、URL字段和HTTP协议版本。GET请求参数应该是在请求行
            例如:GET /index.html HTTP/1.1
                get方法将数据拼接在url后面,传递参数受限
            请求方法:
                GET、POST、HEAD、PUT、DELETE、OPTIONS、TRACE、CONNECT
请求头:(key,value形式)
   User-Agent:产生请求的浏览器类型。
            Accept:客户端可识别的内容类型列表。
            Host:主机地址
等等
请求体:
GET形式没有,POST把请求数据放在这
响应(响应行+响应头+响应体)
响应行:报文协议及版本和状态码,状态描述,例如HTTP/1.1 200 ok
响应头:
包含服务器类型,日期,长度,内容类型等
Server:Apache Tomcat/5.0.12
Date:Mon,6Oct2003 13:13:33 GMT
Content-Type:text/html
Last-Moified:Mon,6 Oct 2003 13:23:42 GMT
Content-Length:112
 响应体:响应正文就是服务器返回的HTML页面或者json数据
 

参考:https://www.jianshu.com/p/eb3e5ec98a66

https://www.jianshu.com/p/eb3e5ec98a66

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

HttpURLConnect调用URL关闭,一直调用卡住不动。只用connect timeout,没有read timeout

connect timeout 是建立连接的超时时间;
read timeout,是传递数据的超时时间。

 1 public  String getConn(String str) {
 2         String url = "";
 3         String validateResult = null;
 4         HttpURLConnection con = null;
 5         BufferedInputStream bis = null;
 6         if(TypeChecker.isEmpty(url)) {
 7             system.out.println("URL NULL!");
 8             return null;
 9         }
10         try {
11             URL dataUrl = new URL(url);
12             con = (HttpURLConnection) dataUrl.openConnection();
13             system.out.println("url ="+url);
14             system.out.println("postData ="+str);
15             con.setRequestMethod("POST");
16             con.setRequestProperty("Content-Type","text/xml;charset=utf-8");
17             con.setDoOutput(true);
18             con.setDoInput(true);
19             con.setAllowUserInteraction(false);
20             con.setUseCaches(false);
21             con.setConnectTimeout(30*1000);
22             con.setReadTimeout(30*1000);
23             
24             OutputStream os=con.getOutputStream();
25             DataOutputStream dos=new DataOutputStream(os);
26             dos.write(str.getBytes());
27             dos.flush();
28             dos.close();
29             int code = con.getResponseCode();
30             system.out.println("resultCode================:"+code);
31             if (!TypeChecker.isEmpty(code)&&(code == 200||code == 201||code == 202)) {
32                 bis = new BufferedInputStream(con.getInputStream()); 
33             } else {
34                 system.out.println("can not connect URL ,result NULL!");
35                 return null;
36             }
37             
38             bis = new BufferedInputStream(con.getInputStream());
39             BufferedReader br = new BufferedReader(new InputStreamReader(bis, "UTF-8"));
40             String result = "";
41             String readLine = "";
42             while ((readLine = br.readLine()) != null) {
43                  if (readLine.length() > 0)
44                     result += readLine;
45             }
46             system.out.println("result:"+result);
47             if (result != null && result.length() > 0){
48                 validateResult = result;
49             }else{
50                 system.out.println("result NULL!");
51                 return null;
52             }
53         } catch (Exception ex) {
54             system.out.println("receive  Exception: " + ex.getMessage());
55             ex.printStackTrace();
56             return null;
57         }finally{
58          if (bis != null)
59             try {
60                 bis.close();
61             } catch (IOException e) {
62                 // TODO Auto-generated catch block
63                 e.printStackTrace();
64             }
65          if(con != null)
66             con.disconnect();
67         }
68          return validateResult;
69 }
View Code

参考:https://blog.csdn.net/weixin_33720452/article/details/87625209

https://blog.csdn.net/q2232/article/details/48136973

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

遍历集合删除元素
 
1、绝对错误的方式
  1. List list = xxxService.getAll();  
  2. for(Object obj : list ){  
  3.      list.remove(obj );  //此方式必然导致ConcurrentModificationException  
  4. }  
2、使用Iterator重构,但不够彻底,出现同样的异常,却难以排查。
 
Java代码  收藏代码
  1. List list = xxxService.getAll();  
  2. for(Iterator objIter =  list.iterate();obj.hasNext(); ){  
  3.      list.remove(obj );  //此方式也导致ConcurrentModificationException  
  4. }  
 报错:

Exception in thread "main" java.util.ConcurrentModificationException
at java.util.LinkedList$ListItr.checkForComodification(Unknown Source)
at java.util.LinkedList$ListItr.next(Unknown Source)

 
Java代码  收藏代码
  1. List list = xxxService.getAll();  
  2. for(Iterator objIter =  list.iterate();obj.hasNext(); ){  
  3.      objIter .remove(); 
  4. }  
 转载:https://www.iteye.com/blog/neo19860208-1500124
原文地址:https://www.cnblogs.com/jingRegina/p/11338490.html