ZF2 - 发布到远程URL时的Cookie异常标头

时间:2014-03-19 12:50:06

标签: php zend-framework cookies zend-framework2

我试图通过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=)

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

代码在正常路径中工作OKAY ...当我从控制台运行它时,它只会抱怨cookie问题。

1 个答案:

答案 0 :(得分:0)

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

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