开发者

Getting query String using HttpClient 4.1

I am migrating to Httpclient 4.1 from HttpClient 3.0 How can I get the query String from the URL.

client = new DefaultHttpClient();

client.getHostConfiguration().setHost( pro.getProperty( "host" ),
                Integer.parseInt( pro.getProperty( &qu开发者_运维知识库ot;port" ).trim() ),
                    pro.getProperty( "protocol" ) );
//client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

client.getCredentialsProvider().setCredentials(
        new AuthScope( pro.getProperty( "host" ),
            Integer.parseInt( pro.getProperty( "port" ).trim() ),
                pro.getProperty( "protocol" ) ),
        new UsernamePasswordCredentials( user, userpassword ) );

client.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true );
authget = new HttpGet( pro.getProperty( "getparam" ) );
HttpResponse response = client.execute( authget );
HttpEntity entity = response.getEntity();

What should I insert here for getting the query string to match from "&".

StringTokenizer qryStrToken = new StringTokenizer(***Insert code for getting query string***,"&");

while (qryStrToken.hasMoreTokens()){
    String temp = qryStrToken.nextToken();
    if(temp.startsWith("SMAGENTNAME")){
        smAgentName = temp.substring(temp.indexOf("=")+1);
    }
}


Use the getUri method of HttpGet.

String uri = authGet.getURI();


The URI has your query string which you can get by:

URLEncodedUtils.parse(new URI(request.getRequestLine().getUri()),HTTP.UTF_8);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜