繁体   English   中英

如何在Android的HttpURLConnection中发送HTTP SEARCH请求?

[英]how to send a HTTP SEARCH request in HttpURLConnection on Android?

我想知道是否有可能(实际上)通过java.net.HttpURLConnection向基于HTTP的URL发送SEARCH请求。

我已经阅读了许多描述如何发送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的信息。

首先,我不知道我的方法是否最佳。

我正在使用restful codeigniter webservice 我为实现search所做的工作是使用POST 我只发布了搜索关键字 ,然后我的webservice将执行SQL Query以在SQL Query中搜索该String (关键字)。

根据文档 ,setRequestMethod()不允许使用SEARCH方法(这很有意义,因为据我所知SEARCH MS 。但是,您始终可以尝试使用setRequestMethod()看看会发生什么。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM