gpt4 book ai didi

java - 使用 HttpClient 4.1 获取查询字符串

转载 作者:行者123 更新时间:2023-12-01 05:48:37 24 4
gpt4 key购买 nike

我正在从 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);
}
}

最佳答案

使用HttpGet的getUri方法。

String uri = authGet.getURI();

关于java - 使用 HttpClient 4.1 获取查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5259797/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com