Error parsing HTTP request header--400 bad request
問題描述:
JSP中通過form post方式請求URL傳入json格式引數報錯:
資訊: Error parsing HTTP request header
Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
at org.apache.coyote.http11.InternalAprInputBuffer.parseRequestLine(InternalAprInputBuffer.java:235)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1028)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2549)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2538)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
var data =
{
"ids": [
"0654B61D-5946-4875-A801-392DBEAB55F0"
],
"docId": "6E846CE4-A818-443A-9A0A-28017084609A"
};
這是我的請求:.../dataCenter/addEditDoc.do?command=fileDownload&data=JSON.stringify(data);
問題原因:
查資料瞭解到最新的tomcat6 7 8 都有這個問題,這個問題是由於tomcat的新版本增加了一個新特性,就是嚴格按照 RFC 3986規範進行訪問解析,
而 RFC 3986規範定義了Url中
只允許包含英文字母(a-zA-Z)、數字(0-9)、-_.~4個特殊字元以及所有保留字元(RFC3986中指定了以下字元為保留字元:! * ’ ( ) ; : @ & = + $ , / ? # [ ])。
解決方法:
對json字串中大括號進行URL編碼,結果為:
/dataCenter/addEditDoc.do?command=fileDownload&data="+JSON.stringify(data).replace('{','%7B').replace('}','%7D');
PS: ASCII字元與URL編碼的對照表:
ASCII字元 URL編碼
空格 %20
! %21
" %22
# %23
$ %24
% %25
& %26
' %27
( %28
) %29
* %2A
+ %2B
, %2C
- %2D
. %2E
/ %2F
0 %30
1 %31
2 %32
3 %33
4 %34
5 %35
6 %36
7 %37
8 %38
9 %39
: %3A
; %3B
< %3C
= %3D
> %3E
? %3F
@ %40
A %41
B %42
C %43
D %44
E %45
F %46
G %47
H %48
I %49
J %4A
K %4B
L %4C
M %4D
N %4E
O %4F
P %50
Q %51
R %52
S %53
T %54
U %55
V %56
W %57
X %58
Y %59
Z %5A
[ %5B
\ %5C
] %5D
^ %5E
_ %5F
` %60
a %61
b %62
c %63
d %64
e %65
f %66
g %67
h %68
i %69
j %6A
k %6B
l %6C
m %6D
n %6E
o %6F
p %70
q %71
r %72
s %73
t %74
u %75
v %76
w %77
x %78
y %79
z %7A
{ %7B
| %7C
} %7D
~ %7E
%7F
€ %80
%81
‚ %82
ƒ %83
„ %84
… %85
† %86
‡ %87
ˆ %88
‰ %89
Š %8A
‹ %8B
Œ %8C
%8D
Ž %8E
%8F
%90
‘ %91
’ %92
“ %93
” %94
• %95
– %96
— %97
˜ %98
™ %99
š %9A
› %9B
œ %9C
%9D
ž %9E
Ÿ %9F
%A0
¡ %A1
¢ %A2
£ %A3
%A4
¥ %A5
| %A6
§ %A7
¨ %A8
© %A9
ª %AA
« %AB
¬ %AC
¯ %AD
® %AE
¯ %AF
° %B0
± %B1
² %B2
³ %B3
´ %B4
µ %B5
¶ %B6
· %B7
¸ %B8
¹ %B9
º %BA
» %BB
¼ %BC
½ %BD
¾ %BE
¿ %BF
À %C0
Á %C1
 %C2
à %C3
Ä %C4
Å %C5
Æ %C6
Ç %C7
È %C8
É %C9
Ê %CA
Ë %CB
Ì %CC
Í %CD
Î %CE
Ï %CF
Ð %D0
Ñ %D1
Ò %D2
Ó %D3
Ô %D4
Õ %D5
Ö %D6
%D7
Ø %D8
Ù %D9
Ú %DA
Û %DB
Ü %DC
Ý %DD
Þ %DE
ß %DF
à %E0
á %E1
â %E2
ã %E3
ä %E4
å %E5
æ %E6
ç %E7
è %E8
é %E9
ê %EA
ë %EB
ì %EC
í %ED
î %EE
ï %EF
ð %F0
ñ %F1
ò %F2
ó %F3
ô %F4
õ %F5
ö %F6
÷ %F7
ø %F8
ù %F9
ú %FA
û %FB
ü %FC
ý %FD
þ %FE
相關文章
- HTTP Status 400 – Bad RequestHTTP
- nginx: 400 Bad Request | The plain HTTP request was sent to HTTPS portNginxAIHTTP
- Spring Mvc Http 400 Bad Request問題排查SpringMVCHTTP
- SpringMVC 404:Bad requestSpringMVC
- ASP.NET MVC got 405 error on HTTP DELETE requestASP.NETMVCGoErrorHTTPdelete
- Servlet&HTTP&RequestServletHTTP
- 400 Bad Request(錯誤請求)
- PHP Simulation HTTP Request(undone)PHPHTTP
- Jmeter之HTTP Request DefaultsJMeterHTTP
- Excel為批註設定圖片背景 出現Bad Request - Request Too longExcel
- Jmeter系列(21)- 詳解 HTTP RequestJMeterHTTP
- HTTP Headers的Request HeadersHTTPHeader
- [Jenkins]Error:403 No valid crumb was included in the requestJenkinsError
- nodejs使用request傳送http請求NodeJSHTTP
- ngx_http_discard_request_body 函式分析HTTP函式
- FND_REQUEST.SUBMIT_REQUEST和 FND_CONCURRENT.WAIT_FOR_REQUESTMITAI
- nodejs Error: request entity too large解決方案NodeJSError
- Request物件物件
- android模擬器 一個錯誤:X Error of failed request: BadRequest (invalid request code or no such operation)...AndroidErrorAI
- 關於FND_REQUEST.SUBMIT_REQUEST和 FND_CONCURRENT.WAIT_FOR_REQUESTMITAI
- ngx_http_request_t結構體詳解HTTP結構體
- http request-01-XMLHttpRequest XHR 簡單介紹HTTPXML
- 基礎篇-http協議《http 簡介、url詳解、request》HTTP協議
- 【等待事件】global cache cr request/gc current request事件GC
- request.getRequestURI 與request.getServletPath() 區別Servlet
- Git Fork Pull Request(PR)和Merge Request(MR)Git
- ABAP 辨析ON INPUT|REQUEST|CHAIN-INPUT|CHAIN-REQUESTAI
- Django中的request.GET和request.POSTDjango
- urllib.request.Request物件封裝請求物件封裝
- 使用 request 和 cheerio 庫來傳送 HTTP 請求HTTP
- http協議學習-請求頭Request HeadersHTTP協議Header
- HTTP請求中 request payload 和 formData 區別?HTTPORM
- request爬蟲爬蟲
- request與HttpResponseHTTP
- Request: credentials property
- git push fatal: HttpRequestException encountered. An error occurred while sending the requestGitHTTPExceptionErrorWhile
- 關於 Angular HTTP Interceptor 中 Request 和 Response 的 immutable 特性AngularHTTP
- http協議學習系列(請求頭---Request Headers)HTTP協議Header