CodingJungle Posted July 22, 2022 Posted July 22, 2022 I'm not entirely sure if this is \IPS\Http\Request\Curl bug or a problem with the IPS api, but i'm assuming it is a problem with \IPS\Http\Request\Curl cause when forcing \IPS\Http\Request\Sockets this error doesn't happen. example code: $category = 2; $author = 1; $communityUrl = 'http://codingjungle.test/dev'; $apiKey = '214befc90239f63bc16dd89b4dfbd300'; $endpoint = '/downloads/files'; $response = \IPS\Http\Url::external($communityUrl . '/api/index.php?' . $endpoint. '&key=' . $apiKey)->request()->get(['category' => $category]); if i send the API parameters in get, I receive the following response: { "errorCode": "1S303\/8", "errorMessage": "NO_AUTHOR" } which is strange, cause when i got look up this error, i only find it in \IPS\downloads\api\files\POSTindex, but i'm calling $response->get(), so i should be hitting \IPS\downloads\api\files\GETindex with that endpoint. looking a bit further into what is going, this code is in \IPS\Http\Request\Curl::get() /** * HTTP GET * * @param mixed $data Data to send with the GET request * @return \IPS\Http\Response * @throws \IPS\Http\Request\CurlException */ public function get( $data=NULL ) { /* Specify that this is a GET request */ curl_setopt( $this->curl, CURLOPT_HTTPGET, TRUE ); $this->dataForLog = NULL; if ( $data ) { curl_setopt( $this->curl, CURLOPT_POSTFIELDS, $data ); } return $this->_executeAndFollowRedirects( 'GET', NULL ); } it appears the CURLOPT_POSTFIELDS is triggering the POST for the API instead of GET (when i use this same code, by using \IPS\Http\Request\Sockets::get() instead by setting \IPS\BYPASS_CURL to true, it works as intended. i get the requested data from the API). I believe the \IPS\Http\Request\Curl::get() should be: /** * HTTP GET * * @param mixed $data Data to send with the GET request * @return \IPS\Http\Response * @throws \IPS\Http\Request\CurlException */ public function get( $data=NULL ) { /* Specify that this is a GET request */ curl_setopt( $this->curl, CURLOPT_HTTPGET, TRUE ); $this->dataForLog = NULL; if ( \is_array($data) && empty($data) === false ) { $this-url->setQueryString($data); } elseif( $data !== null){ $queryString = []; \parse_str($foo, $queryString ); $this-url->setQueryString($queryString); } return $this->_executeAndFollowRedirects( 'GET', NULL ); } SeNioR- 1
Recommended Posts