POST /autoPalletCAN?pEvent=openBagSignal HTTP/1.1
Host: 192.168.11.1:9000
User-Agent: workerman/http-client
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded, application/json
Content-Length: 627
RT
如果設置了的話Content-Type 會出現(xiàn)多個值,在某些接口上會報錯。
上面是抓色的結果。要發(fā)送的Content-Type 是 application/json 但是會出現(xiàn)多個值。
用是這么用的
$http1->request($url, [
'method' => 'POST',
'version' => '1.1',
'headers' => ['Connection' => 'keep-alive'],
'headers' => ['Content-type'=>'application/json'],
'data' => [$post],
'success' => function ($response) {
echo $response->getBody();
},
'error' => function ($exception) {
$ident = 'SAC2WorkStation';
new logErr($ident,$exception);
}
]);
上次設置Connection好像出有類似問題。
Request.php 這樣改一下解決了。
public function end($data = '')
{
if (($data || $data === '0' || $data === 0) || $this->getBody()->getSize()) {
if (!isset($this->_options['headers']['Content-Type'])) {
$this->withHeader('Content-Type', 'application/x-www-form-urlencoded');
}
$this->withHeader('Content-Type', $this->_options['headers']['Content-Type']);
}