2013-04-02 64 views
0

有人可以帮助我更好地理解此代码。GET方法解析

// request method is GET 
DefaultHttpClient httpClient = new DefaultHttpClient(); 
String paramString = URLEncodedUtils.format(params, "utf-8"); 
url += "?" + paramString; 
HttpGet httpGet = new HttpGet(url); 
HttpResponse httpResponse = httpClient.execute(httpGet); 
HttpEntity httpEntity = httpResponse.getEntity(); 
is = httpEntity.getContent(); 

主要是我只是需要帮助搞清楚URL部分。

url + =“?” + paramString;

我该如何更好地定制代码的那部分?

在定制我想利用我的当前URL

academic_programs_xml/oncampus-departments.xml

,并更改为

academic_programs_xml/oncampus-associates.xml

我的想法是,你可以采取的URL位置

academic_programs_xml/

然后帕拉姆添加到URL然后添加的.xml

这样的可能?

url + = paramString +“.xml”;

+0

http://jodd.org/doc/http.html –

+1

你能不能约你的意思是“自定义部分” –

+0

在定制我想利用我的当前URL一滴透明的 academic_programs_xml/oncampus-部门.xml 并将其更改为 –

回答

1

这里我们将参数添加到URL 让我们举个例子吧。

Base URL : www.example.com/index.php 

如果我们要添加的参数{搜索=你好}

那么我们就会这样做这样

Param URL : www.example.com/index.php?search=hello 

基本上,什么后?标记在URL的末尾,是关键值 配对参数。

现在回到你的代码,你添加一个问号的代码

url += "?" + paramString; 
后的代码

String paramString = URLEncodedUtils.format(params, "utf-8"); 

这样,你就追加到URL创建参数键值对的字符串

我希望这很清楚。

+0

这很完美!感谢它实际上完美回答了我的问题! –

0

在计算出: “?”标记URI路径部分的结束和查询字符串的开始。查询字符串通常用于编码参数,例如在调用Web服务期间。

关于定制,目前尚不清楚你的意思。