使用 HttpClient 4.1 获取查询字符串

发布于 2024-10-21 05:52:03 字数 1254 浏览 1 评论 0原文

我正在从 HttpClient 3.0 迁移到 Httpclient 4.1 如何从 URL 中获取查询字符串。

client = new DefaultHttpClient();

client.getHostConfiguration().setHost( pro.getProperty( "host" ),
                Integer.parseInt( pro.getProperty( "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();

我应该在此处插入什么以使查询字符串与“&”相匹配。

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);
    }
}

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( "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);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

从来不烧饼 2024-10-28 05:52:03

使用HttpGet的getUri方法。

String uri = authGet.getURI();

Use the getUri method of HttpGet.

String uri = authGet.getURI();
盛夏尉蓝 2024-10-28 05:52:03

URI 包含您的查询字符串,您可以通过以下方式获取:

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文