PHP内でcURLを使用するのが難しいです。私はこれを "翻訳"するために何をする必要があるのかよくわかりません:cURLをPHPに翻訳する
curl -X POST -u "{username}:{password}" --header "Content-Type: application/json" --data-binary @profile.json "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2016-10-20&consumption_preferences=true&raw_scores=true"
へのPHPへの実行。
これは私がこれまで持っているすべてのですが、私は似ても似つかないよように私は感じている:
$url2 = 'https://watson-api-explorer.mybluemix.net/personality-insights/api/v3/profile?raw_scores=false&csv_headers=false&consumption_preferences=true&version=2017-02-01';
$request_headers = array();
$request_headers[] = 'Accept: application/json';
$request_headers[] = 'Content-Type: text/plain';
$request_headers[] = 'Content-Language: en';
$request_headers[] = 'Accept-Language: en';
$ch2 = curl_init($url2);
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $myvars2);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch2, CURLOPT_HEADER, $request_headers);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
$response2 = curl_exec($ch2);
var_dump($response2);
実際にあなたはかなり近づいています。あなたはちょうど私が見ているものから認証ピースを紛失しています。上のスクリプトから何の出力を得ていますか? – JakeParis
それは私が詰まっていると思う作品です。私は '-u'が何であるか、それをPHPにどのように"翻訳 "するかを知らない。私はヘッダーを見つけましたが、それはそれです。 – jonmrich