我使用HTTP SEARCH请求将变量发布到某个在线.php文件中。但是,不知怎的,我没有工作。虽然,该应用程序正在使用"网络权限"但仍然。它显示错误。 以下是我的代码:
public static final String SEARCH_URL = "http://www.example.com/search/";
public void onSearchAPI() {
String title = "title";
String message = "message";
String httpUrl = SEARCH_URL;
String resultData = "";
URL url = null;
try {
url = new URL(httpUrl);
} catch (MalformedURLException e) {
Log.e("Debug", "MalformedURLException");
}
if (url != null) {
try {
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.setDoOutput(true);
urlConn.setDoInput(true);
urlConn.setRequestMethod("SEARCH");
urlConn.setUseCaches(false);
urlConn.setInstanceFollowRedirects(true);
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConn.connect();
DataOutputStream out = new DataOutputStream(urlConn.getOutputStream());
String content = "title=" + URLEncoder.encode(title, "UTF-8")
+ "&message=" + URLEncoder.encode(message, "UTF-8");
Log.e("Debug", "Params :" + content);
out.writeBytes(content);
out.flush();
out.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String inputLine = null;
while (((inputLine = reader.readLine()) != null)) {
resultData += inputLine + "\n";
}
reader.close();
urlConn.disconnect();
if (resultData != null) {
Log.d("GetSearchAPI", "URL: " + SEARCH_URL + ", RESPONSE : " + resultData);
processGetSearch(resultData);
} else {
Log.d("GetPeopleAPI", "No results");
}
} catch (IOException e) {
Log.e("Debug", "IOException");
}
} else {
Log.e("Debug", "Url NULL");
}
}
在这里," urlConn.setRequestMethod(" SEARCH")"是错误。 我想知道在android上使用HTTP SEARCH请求的方法。 请帮我。