有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何发送可以被php读取的post参数

我与url有一些联系:

HttpURLConnection connection = (HttpURLConnection) url.openConnection();

如何将post参数发送到php函数http://www.php.net/manual/en/reserved.variables.request.php可以读取的url?我试图回答这个问题:Java - sending HTTP parameters via POST method easily但没有成功。它只显示空数组

php代码:

print_r($_REQUEST,1)

java代码:

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("category_name", categoryName);
connection.setRequestProperty("complete", complete);

DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
connection.getResponseCode();

wr.flush();
wr.close();
connection.disconnect();

共 (0) 个答案