获取响应对象

@return \Yurun\Util\YurunHttp\Http\Response
773537
private function getResponse()
    {
        // 分离header和body
        $headerSize = curl_getinfo($this->handler, CURLINFO_HEADER_SIZE);
        $headerContent = substr($this->curlResult, 0, $headerSize);
        $body = substr($this->curlResult, $headerSize);
        // PHP 7.0.0开始substr()的 string 字符串长度与 start 相同时将返回一个空字符串。在之前的版本中，这种情况将返回 FALSE 。
        if(false === $body)
        {
            $body = '';
        }

        // body
        $this->result = new Response($body, curl_getinfo($this->handler, CURLINFO_HTTP_CODE));

        // headers
        $rawHeaders = explode("\r\n\r\n", trim($headerContent), 2);
        $requestCount = count($rawHeaders);
        for($i = 0; $i < $requestCount; ++$i)
        {
            $allHeaders[] = $this->parseHeaderOneRequest($rawHeaders[$i]);
        }
        if($requestCount > 0)
        {
            $headers = $allHeaders[$requestCount - 1];
            foreach($headers as $name => $value)
            {
                $this->result = $this->result->withAddedHeader($name, $value);
            }
        }
        
        // cookies
        $cookies = [];
        $count = preg_match_all('/set-cookie\s*:\s*([^\r\n]+)/i', $headerContent, $matches);
        for($i = 0; $i < $count; ++$i)
        {
            $list = explode(';', $matches[1][$i]);
            $count2 = count($list);
            if(isset($list[0]))
            {
                list($cookieName, $value) = explode('=', $list[0], 2);
                $cookieName = trim($cookieName);
                $cookies[$cookieName] = array('value'=>$value);
                for($j = 1; $j < $count2; ++$j)
                {
                    $kv = explode('=', $list[$j], 2);
                    $cookies[$cookieName][trim($kv[0])] = isset($kv[1]) ? $kv[1] : true;
                }
            }
        }
        $this->result = $this->result->withCookieOriginParams($cookies)
                                    ->withError(curl_error($this->handler))
                                    ->withErrno(curl_errno($this->handler));

        curl_close($this->handler);
    }
932498
public function actionAdopt()
    {
        $answerId = Yii::$app->request->post('answerId');
        $answer = $this->findModel($answerId);
        if (Yii::$app->user->id !== $answer->question->user_id) {
            Yii::$app->session->setFlash('danger', Yii::t('question', 'You can not take your own answer.'));
            return $this->redirect(['/question/question/view', 'id' => $answer->question_id]);
        }

        $transaction = Yii::$app->db->beginTransaction();
        try {
            $answer->adopted_at = time();
            $answer->save();
            $answer->question->status = Question::STATUS_END;
            $answer->question->save(false);

            if (isset(Yii::$app->user->identity->extend->adoptions)) {
                Yii::$app->user->identity->extend->updateCounters(['adoptions' => 1]);
            }
            if (function_exists('credit')) {
                /*悬赏处理*/
                if ($answer->question->price > 0) {
                    credit($answer->user_id, 'answer_adopted', $answer->question->price, $answer->question->id, $answer->question->title);
                }
            }

            $transaction->commit();
            Yii::$app->session->setFlash('success', Yii::t('question', 'Answer to adopt success.'));
            return $this->redirect(['/question/question/view', 'id' => $answer->question_id]);
        } catch (\Exception $e) {
            Yii::$app->session->setFlash('danger', Yii::t('question', 'Adopte failed. Please try again later.'));
            return $this->redirect(['/question/question/view', 'id' => $answer->question_id]);
        }
    }
1229063
public function response()
    {
        return new MultiErrorResponse($this->httpStatusCode, $this->code, $this->message, $this->validationMessages);
    }
111390
public function getResult() {
		if (!$this->result && $this->response && $this->response->getHttpStatus() >= 200 && $this->response->getHttpStatus() < 300) {
			// decode the response
			$this->result = json_decode($this->response->getRawResponse());
		}

		return $this->result;
	}
828643
public function execute()
    {
        $id = $this->getRequest()->getParam('ruleid');
        $attribute = $this->getRequest()->getParam('attribute');
        $arrayKey = $this->getRequest()->getParam('arraykey');
        $conditionName = $this->getRequest()->getParam('condition');
        $valueName = $this->getRequest()->getParam('value');

        if ($arrayKey && $id && $attribute && $conditionName && $valueName) {
            $rule = $this->rulesFactory->create();
            $this->rulesResource->load($rule, $id);
            //rule not found
            if (!$rule->getId()) {
                $this->http->getHeaders()->clearHeaders();

                return $this->http->setHeader(
                    'Content-Type',
                    'application/json'
                )->setBody('Rule not found!');
            }
            $conditions = $rule->getCondition();
            $condition = $conditions[$arrayKey];
            $selectedConditions = $condition['conditions'];
            $selectedValues = $condition['cvalue'];
            $type = $this->ruleType->getInputType($attribute);
            $conditionOptions = $this->ruleCondition->getInputTypeOptions($type);

            $response['condition'] = str_replace(
                'value="' . $selectedConditions . '"',
                'value="' . $selectedConditions . '"' . 'selected="selected"',
                $this->getOptionHtml(
                    'conditions',
                    $conditionName,
                    $conditionOptions
                )
            );

            $elmType = $this->ruleValue->getValueElementType($attribute);

            $this->evaluateElmType($elmType, $selectedConditions, $attribute, $selectedValues, $valueName, $response);

            $this->http->getHeaders()->clearHeaders();
            $this->http->setHeader('Content-Type', 'application/json')
                ->setBody($this->jsonEncoder->jsonEncode($response));
        }
    }
758145
public function getResponse()
    {
        $curl = curl_init();

        $this->addParameters()->addHeaders();
        $this->options[CURLOPT_RETURNTRANSFER] = true;
        curl_setopt_array($curl, $this->options);

        $response = curl_exec($curl);

        $this->meta = array(
            'info'             => curl_getinfo($curl, CURLINFO_HTTP_CODE),
            'error_message'    => curl_errno($curl),
            'error_code'    => curl_error($curl));

        curl_close($curl);
        unset($curl);

        return $response;
    }
283757
protected function getResponse(){

        $post = false;

        // use output parameter if required by the service
        $this->requestUrl.= $this->service['endpoint']
                            ? $this->endpoint
                            : '';

        // set API Key
        $this->requestUrl.= 'key='.urlencode( $this->key );


        switch( $this->service['type'] ){

            case 'POST':

                    $post =  json_encode( $this->service['param'] );

                break;


            case 'GET':
            default:
                    $this->requestUrl.='&'. Parameters::getQueryString( $this->service['param'] );
                break;
        }


        return $this->make( $post );

    }
1285449
protected function response()
    {
        if ( $this->responseObject ) {
            return $this->responseObject;
        }
        $this->responseObject = new Response;

        return $this->responseObject;
    }
878823
public function getResponse()
    {
        $this->addParameters()->addHeaders();
        $this->options[CURLOPT_RETURNTRANSFER] = true;

        $this->meta = call_user_func($this->map, $this->options);

        return $this->meta['response'];
    }
86266
public function save()
    {
        $input              = Input::all();
        $session            = app('request')->session();
        $classname          = array_get($input, 'classname');
        $key                = uri();
        $params             = $session->get($key);
        $params[$classname] = array_get($input, 'params');
        $session->put($key, $params);
        $session->save();
        return response(app($classname)->sidebar($params[$classname]), 200);
    }
529136
public function run()
    {
        /* @var $model Model */
        $model = Yii::createObject($this->modelClass);
        $event = Yii::createObject(['class' => FormEvent::class, 'form' => $model]);

        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            $this->trigger(self::EVENT_BEFORE_SAVE, $event);

            $this->saveSettings($model);

            $this->trigger(self::EVENT_AFTER_SAVE, $event);

            if ($this->successMessage !== null) {
                Yii::$app->session->setFlash('success', $this->successMessage);
            }

            return $this->controller->refresh();
        }

        $this->prepareModel($model);

        return $this->controller->render($this->view, ArrayHelper::merge($this->viewParams, [
            'model' => $model,
        ]));
    }
1078362
public function run()
    {
        $option = $this->rule->getOption();

        // 检测路由after行为
        if (!empty($option['after'])) {
            $dispatch = $this->checkAfter($option['after']);

            if ($dispatch instanceof Response) {
                return $dispatch;
            }
        }

        // 数据自动验证
        if (isset($option['validate'])) {
            $this->autoValidate($option['validate']);
        }

        $data = $this->exec();

        return $this->autoResponse($data);
    }
47557
public function execute()
    {
        $this->determineMethod();

        $this->user->{$this->method}();

        return Response::passed($this->getMessage())
            ->route('admin.users.index');
    }
591820
public function getHttp()
    {
        if (!$this->http) {
            $this->http = new Http();
            $this->http->setRequest($this);
        }

        return $this->http;
    }
525109
public function getResponse()
    {
        $response = redirect()->to($this->getRedirectUrl());
        $response->withInput($this->request->input());
        $response->withErrors($this->getErrors(), 'default');
        $response->setCharset(config('app.charset', 'UTF-8'));

        return $response;
    }
784777
public function handler(): Response
    {
        $member = $this->getAuth();
        return response([
            'id' => $member->getId(),
            'username' => $member->getUsername(),
            'role' => [
                'id' => $member->getRole()->getId(),
                'name' => $member->getRole()->getName()
            ],
            'name' => $member->getName()
        ]);
    }
519438
public final function request()
    {
        if ($this->request == null){
            $this->request = $this->phpContext->createRequest();
        }

        return $this->request;
    }