ZF2 -发送到远程url时Cookie异常报头


ZF2 - Cookie exception header when posting to remote url

我试图通过cURL从zend框架2控制台路由内发布表单。

我正在做类似

的事情
php public/index.php myroute

从终端调用路由。在该路由中有以下内容:

$request = new 'Zend'Http'Request;
$request->setMethod('POST'); 
$request->setUri('http://somesite.com');
$request->getHeaders()->addHeaders([
         'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'
]);
/* set post fields */
$aData = array('hello' => 'world');
$request->setContent($request->getPost()->toString());
/* just to look at request string in console */
echo $request->toString()."'n";
/* post the data */
$client = new 'Zend'Http'Client;
$client->setAdapter("Zend'Http'Client'Adapter'Curl");
$response = $client->dispatch($request);

问题是当从控制台运行时抛出一个cookie异常:

POST http://somesite.com HTTP/1.1
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
hello=world
======================================================================
   The application has thrown an exception!
======================================================================
 Zend'Http'Header'Exception'InvalidArgumentException
 Cookie name cannot contain these characters: =,; 't'r'n'013'014 (WEBUK=)

如果有人能指出如何解决这个问题,我将非常感激。

代码在正常路由下工作当我从控制台运行它时,它只抱怨cookie问题。

现在修复了我的问题。我决定放弃使用zf2方法,而只是使用Guzzle。

$aData = array('hello' => 'world'); 
$httpClient = new GuzzleHttp();         
$r = $httpClient->post('http://somesite.com', [
          'body' => $aData
]);
$response = $httpClient->send($r);