[英]how to send a HTTP SEARCH request in HttpURLConnection on Android?
I want to know if it is possible to send SEARCH request (practically) through java.net.HttpURLConnection to HTTP-based URL. 我想知道是否有可能(实际上)通过java.net.HttpURLConnection向基于HTTP的URL发送SEARCH请求。
I have read so many articles describing that how to send GET, POST, DELETE requests but I still haven't found any sample code which successfully performs SEARCH request. 我已经阅读了许多描述如何发送GET,POST,DELETE请求的文章,但是我仍然没有找到成功执行SEARCH请求的示例代码。
here is sample code. 这是示例代码。
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;
}
in this code, HttpSearch is error. 在此代码中,HttpSearch错误。 please help me about HttpSearch. 请帮助我有关HttpSearch的信息。
First, i dont know whether my approach is best or not. 首先,我不知道我的方法是否最佳。
Im using restful codeigniter webservice
. 我正在使用restful codeigniter webservice
。 What i did to implement search
is by using POST
. 我为实现search
所做的工作是使用POST
。 I simply POST the search keyword and then my webservice
will perform SQL Query
to search that String
(keyword) im my database. 我只发布了搜索关键字 ,然后我的webservice
将执行SQL Query
以在SQL Query
中搜索该String
(关键字)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.