linslin\yii2\curl\Curl::post PHP Method

post() public method

Start performing POST-HTTP-Request
public post ( string $url, boolean $raw = true ) : mixed
$url string
$raw boolean if response body contains JSON and should be decoded
return mixed response
    public function post($url, $raw = true)
    {
        return $this->_httpRequest('POST', $url, $raw);
    }

Usage Example

Exemplo n.º 1
4
 /**
  * @param $username
  * @param $password
  * @return array Success {
  *  @var string AccessId
  *  @var string SecretKey
  *  @var string UserId
  *  @var string EmployeeId
  * }
  * @throws MPAuthException
  */
 public function authenticate($username, $password)
 {
     $data = ['Login' => $username, 'Password' => md5($password)];
     $this->prepareRequest($data);
     try {
         $response = $this->curl->post($this->url . $this->authRelativeUrl, true);
         try {
             $decodedResponse = Json::decode($response, true);
             switch ($decodedResponse['status']['code']) {
                 case 'ok':
                     break;
                 case 'error':
                     throw new MPAuthException('Invalid username or password.');
                     break;
                 default:
                     throw new MPAuthException('Unknown response status.');
             }
             return $decodedResponse['data'];
         } catch (InvalidParamException $e) {
             throw new MPAuthException('Error decoding server response. Raw response: ' . var_export($response, true));
         }
     } catch (Exception $e) {
         throw new MPAuthException('Error requesting host:' . $e->getMessage() . $e->getCode());
     }
 }
All Usage Examples Of linslin\yii2\curl\Curl::post