@@ -1232,10 +1232,9 @@ class ConnectionException extends CCException {
12321232 */
12331233
12341234class TokenRequiredError extends CCException {
1235- public function __toString ()
1236- {
1237- return 'No valid token. Use create_token(email, password) to get a new one ' ;
1238- }
1235+ public function __construct () {
1236+ parent ::__construct ("No valid token. Use create_token(email, password) to get a new one " , 0 );
1237+ }
12391238}
12401239
12411240/*
@@ -1461,17 +1460,18 @@ private function _request($resource, $method=HTTP_Request2::METHOD_GET, $data=ar
14611460 $ request = new HTTP_Request2 ($ url );
14621461 $ request ->setConfig ('ssl_verify_peer ' , API ::SSL_VERIFY_PEER );
14631462
1464- $ methods = array (
1465- 'options ' => HTTP_Request2::METHOD_OPTIONS ,
1466- 'get ' => HTTP_Request2::METHOD_GET ,
1467- 'head ' => HTTP_Request2::METHOD_HEAD ,
1468- 'post ' => HTTP_Request2::METHOD_POST ,
1469- 'put ' => HTTP_Request2::METHOD_PUT ,
1470- 'delete ' => HTTP_Request2::METHOD_DELETE ,
1471- 'trace ' => HTTP_Request2::METHOD_TRACE ,
1472- 'connect ' => HTTP_Request2::METHOD_CONNECT
1473- );
1474- $ request ->setMethod ($ methods [strtolower ($ method )]);
1463+ //$methods = array(
1464+ //'options' => HTTP_Request2::METHOD_OPTIONS,
1465+ //'get' => HTTP_Request2::METHOD_GET,
1466+ //'head' => HTTP_Request2::METHOD_HEAD,
1467+ //'post' => HTTP_Request2::METHOD_POST,
1468+ //'put' => HTTP_Request2::METHOD_PUT,
1469+ //'delete' => HTTP_Request2::METHOD_DELETE,
1470+ //'trace' => HTTP_Request2::METHOD_TRACE,
1471+ //'connect' => HTTP_Request2::METHOD_CONNECT
1472+ //);
1473+ //$request->setMethod($methods[strtolower($method)]);
1474+ $ request ->setMethod ($ method );
14751475
14761476 #
14771477 # If the current API instance has a valid token we add the Authorization
@@ -1497,9 +1497,8 @@ private function _request($resource, $method=HTTP_Request2::METHOD_GET, $data=ar
14971497 $ url = $ request ->getUrl ();
14981498 $ url ->setQueryVariables ($ data );
14991499 } else {
1500- // works with post and put
1501- $ request ->addPostParameter ($ data );
1502- $ request ->setBody (http_build_query ($ data ));
1500+ $ request ->setBody (json_encode ($ data ));
1501+ $ headers ['Content-Type ' ] = 'application/json ' ;
15031502 }
15041503 }
15051504
@@ -1509,14 +1508,7 @@ private function _request($resource, $method=HTTP_Request2::METHOD_GET, $data=ar
15091508 # the wild.
15101509 #
15111510 $ headers ['User-Agent ' ] = sprintf ('phpcclib/%s ' , $ this ->_version );
1512- #
1513- # The API expects PUT or POST data to be x-www-form-urlencoded so we
1514- # also set the correct Content-Type header.
1515- #
1516- if (strtoupper ($ method ) == 'PUT ' || strtoupper ($ method ) == 'POST ' ) {
1517- $ headers ['Content-Type ' ] = 'application/x-www-form-urlencoded ' ;
1518- }
1519- #
1511+ #
15201512 # We also set the Content-Length and Accept-Encoding headers.
15211513 #
15221514 //$headers['Content-Length'] = strlen($body);
0 commit comments