[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-1204?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13290876#comment-13290876
 ] 

yy commented on HTTPCLIENT-1204:
--------------------------------

I have to fix it.
=======================
 httpClient.setRedirectStrategy(new DefaultRedirectStrategy() {

            @Override
            protected URI createLocationURI(String location) throws 
ProtocolException {
                try {
                    int index = location.indexOf("?");
                    if (index != -1) {
                        String url = location.substring(0, index + 1);
                        String params = location.substring(index + 1);
                        StringBuilder sb = new StringBuilder(url);
                        String[] pairs = params.split("&");
                        if (pairs != null && pairs.length > 0) {
                            for (String pair : pairs) {
                                String[] param = pair.split("=", 2);
                                if (param != null && param.length == 2) {
                                    
sb.append(param[0]).append("=").append(URLEncoder.encode(param[1], 
"utf-8")).append("&");
                                }
                            }
                            location = sb.toString();
                        } else if (params.length() > 0) {
                            String[] param = params.split("=", 2);
                            
sb.append(param[0]).append("=").append(URLEncoder.encode(param[1], "utf-8"));
                            location = sb.toString();
                        }
                    }
                } catch (UnsupportedEncodingException e) {
                    logger.error(e.getMessage(), e);
                }
                return super.createLocationURI(location);
            }

        });
                
> redirect error!  java.net.URISyntaxException: Illegal character 
> ----------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1204
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1204
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1.3, 4.2 Final
>         Environment: centos6.2
> jdk1.6u25
>            Reporter: yy
>
> ==========Test.java===================== 
>  HttpClient client = new DefaultHttpClient();
>  HttpGet get = new HttpGet("http://localhost:8080/T/Test";);
>  client.execute(get);
>  client.getConnectionManager().shutdown();
> ==========TestServlet.java=============================
>  protected void doGet(HttpServletRequest request, HttpServletResponse 
> response) throws ServletException, IOException {
>         response.sendRedirect("/xx?name=||dsdf&user=||");
>     }
> ===============================================
> Throws an exception when I run.
> Exception in thread "main" org.apache.http.client.ClientProtocolException
>       at 
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:909)
>       at 
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
>       at 
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
>       at com.Test.main(Test.java:20)
> Caused by: org.apache.http.ProtocolException: Invalid redirect URI: 
> http://localhost:8080/xx?name=||dsdf&user=||
>       at 
> org.apache.http.impl.client.DefaultRedirectStrategy.createLocationURI(DefaultRedirectStrategy.java:189)
>       at 
> org.apache.http.impl.client.DefaultRedirectStrategy.getLocationURI(DefaultRedirectStrategy.java:140)
>       at 
> org.apache.http.impl.client.DefaultRedirectStrategy.getRedirect(DefaultRedirectStrategy.java:209)
>       at 
> org.apache.http.impl.client.DefaultRequestDirector.handleResponse(DefaultRequestDirector.java:1070)
>       at 
> org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:546)
>       at 
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
>       ... 3 more
> Caused by: java.net.URISyntaxException: Illegal character in query at index 
> 30: http://localhost:8080/xx?name=||dsdf&user=||
>       at java.net.URI$Parser.fail(URI.java:2810)
>       at java.net.URI$Parser.checkChars(URI.java:2983)
>       at java.net.URI$Parser.parseHierarchical(URI.java:3073)
>       at java.net.URI$Parser.parse(URI.java:3015)
>       at java.net.URI.<init>(URI.java:577)
>       at 
> org.apache.http.impl.client.DefaultRedirectStrategy.createLocationURI(DefaultRedirectStrategy.java:187)
>       ... 8 more

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to