From YiPs Wiki (i powered)

Watson: Watson

Here is a small php 7 watson script.

Download sample

json request/response (watson_rest_translate.php)

$url="https://watson-api-explorer.mybluemix.net/language-translator/api/v2/translate";
$data = array("model_id"=>"en-ja","text"=>"This is a test");   
$data_string = json_encode($data);
$context  = stream_context_create(
  array('http' => 
    array(
      'method' => 'POST',
      'header' => 'Content-Type: application/json'."\r\n"
                . 'Content-Length: ' . strlen($data_string) . "\r\n"
                . 'accept: application/json'."\r\n",
      'content' => $data_string
    )
  )
);
$ret = file_get_contents($url, false, $context);
var_dump($ret);

how to fix SSL error

 error:14090086:SSL routines:ssl3_get_server_certificate

  > php-cli -r 'var_dump(openssl_get_cert_locations());'
     array(8) {
     ["default_cert_file"]=>
     string(38) "/usr/local/openssl-1.0.2j/ssl/cert.pem"
     :

  > mkdir -p /usr/local/openssl-1.0.2j/ssl/

  > php-cli -r 'ini_set("display_errors", 1);
    $context = stream_context_create(["ssl" =>["verify_peer" => false]]);
    readfile("https://curl.haxx.se/ca/cacert.pem", false, $context);' > /usr/local/openssl-1.0.2j/ssl/cert.pem

Author(s)

Tony “Ranger” Cairns - IBM i PHP / PASE

Retrieved from http://youngiprofessionals.com/wiki/index.php/Watson/Watson
Page last modified on December 07, 2017, at 03:01 PM EST