RestfulなAPIへxmlデータをサーバに送信する際、key無しで送信するためには、以下のように「file_get_contents」関数を使ってファイルデータを取得して、POST 送信する必要がある。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ch2 = curl_init($url); | |
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, FALSE); // -k | |
curl_setopt($ch2, CURLOPT_POST, TRUE); // POST | |
curl_setopt($ch2, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary | |
curl_setopt($ch2, CURLOPT_HTTPHEADER, ['Content-Type: text/xml;charset=utf-8', 'User-Agent: curl']); // Http Header | |
// 返り値を文字列として受け取る場合はONに | |
//curl_setopt($ch2, CURLOPT_RETURNTRANSFER, TRUE); | |
//curl_setopt($ch2, CURLOPT_TRANSFERTEXT, TRUE); | |
//curl_setopt($ch2, CURLOPT_COOKIESESSION, TRUE); | |
curl_setopt($ch2, CURLINFO_HEADER_OUT, TRUE); | |
$xml_flie = 動画のフルパス; | |
$postdata = file_get_contents($xml_flie); | |
curl_setopt($ch2, CURLOPT_POSTFIELDS, $postdata); | |
$response = curl_exec($ch2); |
0 件のコメント:
コメントを投稿