diff --git a/src/YurunHttp/Handler/Curl.php b/src/YurunHttp/Handler/Curl.php index d076821..fbeb0ad 100644 --- a/src/YurunHttp/Handler/Curl.php +++ b/src/YurunHttp/Handler/Curl.php @@ -295,10 +295,10 @@ private function buildCurlHandlerBase(&$request, $handler, &$headers = null, &$s $options[\CURLOPT_RETURNTRANSFER] = true; } // 保存cookie - if (!isset($options[\CURLOPT_COOKIEJAR])) - { - $options[\CURLOPT_COOKIEJAR] = 'php://memory'; - } + // if (!isset($options[\CURLOPT_COOKIEJAR])) + // { + // $options[\CURLOPT_COOKIEJAR] = 'php://memory'; + // } // 允许复用连接 if (!isset($options[\CURLOPT_FORBID_REUSE])) { @@ -324,7 +324,6 @@ private function buildCurlHandlerBase(&$request, $handler, &$headers = null, &$s $this->parseSSL($request, $options); $this->parseProxy($request, $options); $this->parseHeaders($request, $options); - $this->parseCookies($request, $options); $this->parseNetwork($request, $options); curl_setopt_array($handler, $options); } @@ -387,6 +386,7 @@ private function buildCurlHandlerEx(&$request, $handler, $uri = null, $method = { $requestOptions[\CURLOPT_NOBODY] = true; } + $this->parseCookies($request, $requestOptions); curl_setopt_array($handler, $requestOptions); } @@ -649,9 +649,11 @@ private function parseHeadersFormat($request) private function parseCookies(&$request, &$options) { $cookieManager = $this->cookieManager; + $cookie = []; foreach ($request->getCookieParams() as $name => $value) { $cookieManager->setCookie($name, $value); + $cookie[] = $name . '=' . $value; } $cookie = $cookieManager->getRequestCookieString($request->getUri()); if ('' !== $cookie) diff --git a/tests/unit/HttpRequestTest/HttpRequestTest.php b/tests/unit/HttpRequestTest/HttpRequestTest.php index 635f6f4..e78a14a 100644 --- a/tests/unit/HttpRequestTest/HttpRequestTest.php +++ b/tests/unit/HttpRequestTest/HttpRequestTest.php @@ -710,9 +710,9 @@ public function testBug19(): void { $this->call(function () { $http = new HttpRequest(); - $response = $http->head('https://www.bing.com'); + $response = $http->head('https://www.baidu.com'); $this->assertResponse($response); - $response = $http->get('https://www.bing.com'); + $response = $http->get('https://www.baidu.com'); $this->assertResponse($response); $this->assertTrue('' != $response->body()); });