通常、POSTデータを取得すると、HTMLフォームから送信され、パラメーターに名前が付けられます。つまり、から<input type="text" name="yourname" />
、このデータを受信してphpで出力できますecho $_POST['yourname'];
。
現在、XML形式のデータを指定されたURLにPOSTするJavaアプリケーションを実装しています。データのPOSTを試みることができる簡単なPHPページを作成しましたが、データが印刷されません。また、パラメータの名前がないため、PHPでどのように出力するかわかりません。
単純なXMLをサーバーに送信しようとしましたが、サーバーはで応答するはずMESSAGE: <XML>
ですが、応答は。でのみMESSAGE:
です。私は何が間違っているのですか?
これがサーバー上の私のPHPコードです:
<?php
echo 'MESSAGE:';
print_r($_POST); ?>
そして、これがクライアント上の私のJavaコードです。
String xmlRequestStatus = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<test></test>";
String contentType = "text/xml";
String charset = "ISO-8859-1";
String request = null;
try {
request = String.format("%s",
URLEncoder.encode(xmlRequestStatus, charset));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
URL url = null;
URLConnection connection = null;
OutputStream output = null;
InputStream response = null;
try {
url = new URL("http://skogsfrisk.se/test/");
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
connection = url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Accept-Charset", charset);
connection.setRequestProperty("Content-Type", contentType);
output = connection.getOutputStream();
output.write(request.getBytes("ISO-8859-1"));
if(output != null) try { output.close(); } catch (IOException e) {}
response = connection.getInputStream();
...
} catch (IOException e) {
e.printStackTrace();
}