簡體   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