我正在从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( 插入获取查询字符串的代码 ,“&”);
while (qryStrToken.hasMoreTokens())
{
String temp = qryStrToken.nextToken();
if(temp.startsWith("SMAGENTNAME"))
{
smAgentName = temp.substring(temp.indexOf("=")+1);
}
}
答案 0 :(得分:0)
使用HttpGet的getUri方法。
String uri = authGet.getURI();
答案 1 :(得分:0)
URI包含您的查询字符串,您可以通过以下方式获取:
URLEncodedUtils.parse(new URI(request.getRequestLine()。getUri()),HTTP.UTF_8);