public function doAction($request, $iSigner = null, $credential = null, $autoRetry = true, $maxRetryNumber = 3) { if (null == $this->iClientProfile && (null == $iSigner || null == $credential || null == $request->getRegionId() || null == $request->getAcceptFormat())) { throw new ClientException("No active profile found.", "SDK.InvalidProfile"); } if (null == $iSigner) { $iSigner = $this->iClientProfile->getSigner(); } if (null == $credential) { $credential = $this->iClientProfile->getCredential(); } $request = $this->prepareRequest($request); $domain = EndpointProvider::findProductDomain($request->getRegionId(), $request->getProduct()); if (null == $domain) { throw new ClientException("Can not find endpoint to access.", "SDK.InvalidRegionId"); } $requestUrl = $request->composeUrl($iSigner, $credential, $domain); if (count($request->getDomainParameter()) > 0) { $httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(), $request->getDomainParameter(), $request->getHeaders()); } else { $httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(), $request->getContent(), $request->getHeaders()); } $retryTimes = 1; while (500 <= $httpResponse->getStatus() && $autoRetry && $retryTimes < $maxRetryNumber) { $requestUrl = $request->composeUrl($iSigner, $credential, $domain); if (count($request->getDomainParameter()) > 0) { $httpResponse = HttpHelper::curl($requestUrl, $request->getDomainParameter(), $request->getHeaders()); } else { $httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(), $request->getContent(), $request->getHeaders()); } $retryTimes++; } return $httpResponse; }
public function testCurl() { $httpResponse = HttpHelper::curl("ecs.aliyuncs.com"); $this->assertEquals(400, $httpResponse->getStatus()); $this->assertNotNull($httpResponse->getBody()); }