2014-11-13 1 views
2

가 어떻게 머리글이나 내가 사용하고 현재symfony2는

다른 정보가없는 BuzzBundle에서 정확한 내용을 얻을 수 있습니다

$buzz = $this->container->get('buzz'); 
$response = $buzz->get('http://api.ipify.org?format=json'); 
echo $response; 

을 BuzzBundle 응답에서 정확한 콘텐츠를 출력이다

HTTP/1.1 200 OK Server: Cowboy Connection: close Access-Control-Allow-Origin: * Content-Type: text/plain Date: Thu, 13 Nov 2014 14:51:40 GMT Content-Length: 14 Via: 1.1 vegur {"ip":"54.254.210.209"} 

여기에만 {"ip":"111.20.67.90"} 원하는 응답입니다.

또는 다른 방법으로 다른 번들을 사용하거나 PHP 코드에서 컬을 직접 사용해야합니까?

답변

1

후자 인 경우 BuzzBundleinjects the Buzz library into Symfony 인 작은 구성 파일 일뿐입니다. 이것은 당신이 C++에 익숙한 경우 헤더 파일의 바로 상응하는

/** 
* Returns the message document. 
* 
* @return string The message 
*/ 
public function __toString(); 

입니다 : 당신이 Browserget() 방법을 사용하면

, 그것은 a return value of MessageInterfacecall()의 인스턴스 ... 그래서 let's examine that file을 반환 그러나 __toString() 파일이 헤더를 포함하여 전체 메시지를 반환한다는 것이 확실합니다. 우리가 파일의 나머지 부분을 보면 그래서 우리는 찾을 there's another function that gets what you want이 : 그래서

/** 
* Returns the content of the message. 
* 
* @return string The message content 
*/ 
public function getContent(); 

대신 (당신에게 __toString()의 기본 제공) 캐릭터처럼 액세스를 시도하는 개체로 MessageInterface을 치료하는 경우 다음 코드를 사용하십시오.

$buzz = $this->container->get('buzz'); 
$response = $buzz->get('http://api.ipify.org?format=json'); 
echo $response->getContent(); // output: {"ip":"54.254.210.209"}