1

次のリクエストを送信する必要があります。これは、xml の末尾にユーザー名とパスワードを含む XML です。ブラウザーに貼り付けると、これを URL として機能させることができます。

URL?XML=<>...</>&user=123456&password=123456

しかし、curl 呼び出しを作成しようとすると、無効な XML 要求であると表示されます。

POSTFIELDS内にユーザーとパスワードを入れてみました。$trial ='&user=123456&password=123456' の前にそれらを変数として設定しようとしましたが、まだ機能していないようです。

$xml = <<<ENDOFXML
<?xml version="1.0" encoding="UTF-8"?><xmldata>...</xmldata>
ENDOFXML;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'xml='.urlencode($xml).urlencode('&user=123456&password=123456'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_close($ch);
4

1 に答える 1

1

これは間違っています:

curl_setopt($ch, CURLOPT_POSTFIELDS, 'xml='.urlencode($xml).urlencode('&user=123456&password=123456'));

変数名と値のみを urlencode します (変数名に問題がないことがわかっている場合は値のみ):

curl_setopt($ch, CURLOPT_POSTFIELDS, 'xml='.urlencode($xml).'&user=' . urlencode('123456').'&password=' . urlencode('123456'));
于 2013-08-20T08:30:04.493 に答える