http请求中的回车与换行
今天发现个问题,http请求发出去后,一直收不到响应。
因为我是socket发送的,内容是下面这样的:
        String methodContent = "POST /CAD_WebService/GetIncidentTypeDic.do HTTP/1.1\n" +
                "Host: 127.0.0.1:8081\n" +
                "Connection: keep-alive\n" +
                "Content-Length: 0\n" +
                "Sec-Fetch-Mode: cors\n" +
                "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.36 Safari/537.36\n" +
                "Content-Type: application/json\n" +
                "Accept: */*\n" +
                "Origin: chrome-extension://aejoelaoggembcahagimdiliamlcdmfm\n" +
                "Sec-Fetch-Site: cross-site\n" +
                "Accept-Encoding: gzip, deflate, br\n" +
                "Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7\n"
wireshark抓包发现,\n的十六进制为\n。
而正常的http请求(get请求,没有body),其最后为:

所以,因为我只有个0a,当然不行。怎么变成0d0a0d0a呢,在java中如下使用即可:
        String methodContent = "POST /CAD_WebService/GetIncidentTypeDic.do HTTP/1.1\n" +
                "Host: 127.0.0.1:8081\n" +
                "Connection: keep-alive\n" +
                "Content-Length: 0\n" +
                "Sec-Fetch-Mode: cors\n" +
                "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.36 Safari/537.36\n" +
                "Content-Type: application/json\n" +
                "Accept: */*\n" +
                "Origin: chrome-extension://aejoelaoggembcahagimdiliamlcdmfm\n" +
                "Sec-Fetch-Site: cross-site\n" +
                "Accept-Encoding: gzip, deflate, br\n" +
                "Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7\r\n\r\n" ;
https://www.cnblogs.com/runerering/p/6196845.html
上面这个博文说的对,换行都要用System.getProperty("line.separator")才最好。
因为我看正常的http请求:

每一行都是这样的。而我上面的,只有\n。

 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号