I have a rule like:
RewriteCond %{HTTP_HOST}:%{QUERY_STRING} ^(\w+)\.t(.*)\.(\w+)?\.sprawk\.com:(.*)$
RewriteRule ^(.*) /api/translateHtmlPublic?tl=%1&su=%2&p=$1&q=%4 [B,PT,L]
which works great for GET requests.
However, for POST requests, the q parameter is null (which I expected) but inside my Java servlet, both the HttpServletRequest.getReader()
and HttpServletRequest.getInputStream()
give no data.
Using Firefox Live headers, I see that I am sending:
POST /uid/contactSend.cfm HTTP/1.1
Host: fr.t51940.local.sprawk.com
Connection: keep-alive
Referer: http://fr.t51940.local.sprawk.com/uid/contact.cfm?country=137
Cache-Control: max-age=0
Content-Type: application/x-www-form-urlencoded
Content-Length: 146
userName=Nic&queryCountry=Libya&queryCode=137&userEmail=n.cottrell%40idea.int&Comment=Just+testing&captcha=Quotas&Submit=--+Envoyer+Commentaire+--
I know that the servlet is receiving it as a POST
since the doPost
method is triggered. I understand that Apache 2.x should automatically preserve POST data during a simple rewrite, but maybe the addition of parameters is wiping the content data?
Update: I just realised (by dumping out all parameters) that the userName, queryCountry, queryCode parameters are getting correct values via the request.getParameter(String)
method. The problem is that I need to be able to separate the original form parameter names from the ones I introduction in the RewriteRule.
The parameters of a POST are in the body, not the header. You can rewrite the URL as much as you like without affecting them.
The body of a POST request whose content type is application/x-www-form-urlencoded
consists only of parameters that are retrieved via request.getParameter().
Reading the body via request.getInputStream()
and request.getReader()
will deliver nothing. (Servlet Specification 3, #3.1.1)
According to Servlet Specifcation #3, the parameters you add to the URL should be retrievable via getParameter()
.
There is no way to distinguish POST parameters in the body from URL parameters in the header. There is probably therefore something wrong with your solution, or your problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.