GuzzleHttp请求发送乱码

时间:2017-11-23 10:15:28

标签: php utf-8 guzzle6 guzzlehttp

我使用GuzzleHTTP 6.0从API服务器获取数据。由于某种原因,API服务器接收的请求不是UTF-8编码,字符ü,ö,ä,ß是乱码。

我的默认系统和数据库是UTF-8编码的。

我在debug中将true设置为RequestOptions这是输出:

User-Agent: GuzzleHttp/6.2.1 curl/7.47.0 PHP/7.0.22-0ubunut0.16.04.1 Content-type: text/xml;charset="UTF-8" Accept: text/xml" Cache-Control: no-cache Content-Length: 2175 * upload completely sent off: 2175 out of 2175 bytes <HTTP/1.1 200 OK <Server:Apache:Coyote/1.1 <Content-Type: text/xml; charset=utf-8 <Transfer-Encoding: chunked <Date: Thu, 23 Nov 2017 9:34:12 GMT <* Connection #5 to host www.abcdef.com left intact

我已将标题内容明确设置为UTF-8;

    $headers = array(
        'Content-type' => 'text/xml;charset="utf-8"',
        'Accept' => 'text/xml',
        'Content-length' => strlen($requestBody),
    );

我还尝试使用mb_detect_encoding()方法进行测试

mb_detect_encoding($requestBody,'UTF-8',true); // returns UTF-8

任何进一步的想法如何调试此问题.. ??

1 个答案:

答案 0 :(得分:0)

Content-Length必须包含字节数,而不是字符数。这可能是您使用mbstring.func_overload的原因。尝试省略此标题的手动设置,Guzzle将以正确的方式自动设置它。

相关问题