1

通常、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();
}
4

2 に答える 2

3

いいえ、$_POST配列にはmultipart/form-dataenctypeのみが入力されています。

php:// inputラッパーでfopen()を使用するか、$HTTP_RAW_POST_DATAhttp://www.php.net/manual/en/wrappers.php.phpを使用できます

于 2010-06-29T18:03:01.880 に答える
0

xmlを投稿した後、ブラウザでページのソースを表示してみてください。ページを通常どおり表示している場合、htmlspecialchars()に渡さない限り、xmlは表示されません。print_r($_POST);xssなので注意してください。

于 2010-06-29T18:06:21.837 に答える