-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost-data.php
More file actions
60 lines (45 loc) · 1.87 KB
/
post-data.php
File metadata and controls
60 lines (45 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
//
// A very simple PHP example that sends a HTTP POST to a remote site
//
//$data = array($_REQUEST["data"]);
$data = $_REQUEST["data"];
$myfile = file_put_contents('logs.txt', $data.PHP_EOL , FILE_APPEND | LOCK_EX);
//echo $data;
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, "https://gateway.watsonplatform.net/personality-insights/api/v2/profile");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$headers = array();
$headers[] = "Content-Type: text/plain";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERPWD, "aa5e2904-e610-4367-9670-81b5bc30b2d3" . ":" . "cJm6h6ld0Jck");
//$query = http_build_query($data, '', '&');
//$fields = array('data-binary' => $data);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt( $ch , CURLOPT_POSTFIELDS , '@' . $myfile );
$result = curl_exec($ch);
curl_close ($ch);
echo $result;
/*
curl_setopt($ch, CURLOPT_URL,"https://gateway.watsonplatform.net/personality-insights/api");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$headers = ["Content-Type: text/plain"];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS,
'username="aa5e2904-e610-4367-9670-81b5bc30b2d3"&password="cJm6h6ld0Jck"&--data-binary="'+$data+'"');
// in real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS,
// http_build_query(array('postvar1' => 'value1')));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
// further processing ....
//curl_close ($ch);
echo $server_output;*/
?>