0

これは私のcURL POST機能です:

public function curlPost($url, $data)
{
    $fields = '';

    foreach($data as $key => $value) { 
      $fields .= $key . '=' . $value . '&'; 
    }

    rtrim($fields, '&');

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, count($data));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

    $result = curl_exec($ch);
    $info   = curl_getinfo($ch);

    curl_close($ch);
}

$this->curlPost('remoteServer', array(data));

POSTリモートサーバーでを読み取るにはどうすればよいですか?

リモートサーバーはPHPを使用しています...しかし、どの変数$_POST[]を読む必要がありますか

例:-$_POST['fields']または$_POST['result']

4

2 に答える 2

1

コードは機能しますが、他に2つ追加することをお勧めします

A.HTTP302CURLOPT_FOLLOWLOCATIONのため

 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

B.return結果を出力する必要がある場合

return $result ;

function curlPost($url, $data) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
    return $result;
}

print(curlPost("http://yahoo.com", array()));

もう一つの例

    print(curlPost("http://your_SITE", array("greeting"=>"Hello World")));

あなたの投稿を読むためにあなたは使うことができます

 print($_REQUEST['greeting']);

また

 print($_POST['greeting']);
于 2012-10-15T23:29:21.067 に答える
0

通常のPOSTリクエストとして...投稿されたすべてのデータは$_POSTにあります...もちろんファイルを除いて:)&action=request1たとえばURLに追加します

if ($_GET['action'] == 'request1') {

  print_r ($_POST);

}

編集:POST変数を表示するには、POSTハンドラーファイルで次を使用します

if ($_GET['action'] == 'request1') {
  ob_start();
  print_r($_POST);
  $contents = ob_get_contents();
  ob_end_clean();
  error_log($contents, 3, 'log.txt' );
}
于 2012-10-15T23:28:49.753 に答える