2017-11-23 25 views
0

GuzzleHTTP 6.0을 사용하여 API 서버에서 데이터를 가져옵니다. 어떤 이유로 API 서버가 수신 한 요청이 UTF-8로 끝나는 것이 아니며 ü,ö,ä,ß 문자가 깨져서 표시됩니다.GuzzleHttp 요청이 깨진 문자를 전송합니다.

내 기본 시스템 및 데이터베이스는 UTF-8입니다.

는 난이 출력 인 RequestOptionstruedebug을 설정

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

I가 explicitily 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 

더 이상의 아이디어를 사용하여 테스트하려 .. ??

답변

0

Content-Length에는 문자 수가 아니고 바이트 수가 포함되어야합니다. mbstring.func_overload을 사용하면 그 이유가 될 수 있습니다. 이 헤더의 수동 세트를 생략하면 Guzzle이 자동으로 올바르게 설정합니다.