我想知道是否可以通过java.net.HttpURLConnection将SEARCH请求(实际上)发送到基于HTTP的URL。
我已经阅读了很多描述如何发送GET,POST,DELETE请求的文章,但我仍然没有找到任何成功执行SEARCH请求的示例代码。
这是示例代码。
public static String HTTPSearch(String urlAddress, String... searchDataPair) {
HttpParams myParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(myParams, 10000);
HttpConnectionParams.setSoTimeout(myParams, 30000);
DefaultHttpClient hc = new DefaultHttpClient(myParams);
ResponseHandler<String> res = new BasicResponseHandler();
HttpSearch searchMethod = new HttpSearch (urlAddress);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
putDataPair.length / 2);
for (int i = 0; i < putDataPair.length; i += 2) {
nameValuePairs.add(new BasicNameValuePair(searchDataPair[i],
searchDataPair[i + 1]));
}
String response = "";
try {
searchMethod .setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = hc.execute(searchMethod , res);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
在这段代码中,HttpSearch是错误的。 请帮我解决一下HttpSearch。