首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP个性洞察

PHP个性洞察
EN

Stack Overflow用户
提问于 2016-09-11 21:59:58
回答 1查看 290关注 0票数 0
代码语言:javascript
复制
<?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,我遗漏了什么?我应该如何设置这个变量,我应该如何传递我想要分析的文本?

EN

回答 1

Stack Overflow用户

发布于 2016-09-11 22:47:04

在这段php代码中,你刚才赋值给$post_args['body']$data变量是什么。我认为你是在post文件中使用的,所以如果你从url那里得到了一些东西,那就试试吧。

代码语言:javascript
复制
$post_args = array('body' => $_POST['data']) ; 

或者,如果您发送到url,则仅设置一些值。

代码语言:javascript
复制
$data = 'Your real data which you want to send in url  ' ; than use in array .
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39436850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档