<?php
$curl = curl_init();
$post_args = array('body' => $data );
$header_args = array(
'Content-Type: text/plain',
'Accept: application/json'
);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_args);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header_args);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD,"'xxx':'xxx'");
curl_setopt($curl, CURLOPT_URL, "https://gateway.watsonplatform.net/personality-insights/api/v2/profile");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
curl_close($curl);
$decoded = json_decode($result, true);
?>我想在php curl中使用IBM Bluemix Personality Insights,我得到了这个错误:Undefined variable: data,我遗漏了什么?我应该如何设置这个变量,我应该如何传递我想要分析的文本?
发布于 2016-09-11 22:47:04
在这段php代码中,你刚才赋值给$post_args['body']的$data变量是什么。我认为你是在post文件中使用的,所以如果你从url那里得到了一些东西,那就试试吧。
$post_args = array('body' => $_POST['data']) ; 或者,如果您发送到url,则仅设置一些值。
$data = 'Your real data which you want to send in url ' ; than use in array .https://stackoverflow.com/questions/39436850
复制相似问题