这是一个类方法,可以作为Goutte的JSON和URLencoding的示例.
use Goutte\Client;
class a
{
/**
* abstract the request content-type behind one single method,
* since Goutte does not natively support this
* @param string $method HTTP method (GET/POST/PUT..)
* @param string $url URL to load
* @param string $parameters HTTP parameters (POST, etc) to be sent URLencoded
* or in JSON format.
* @return \Symfony\Component\BrowserKit\Response
*/
protected function makeRequest($method, $url, $parameters) {
$client = new Client();
if ($this->requestFormat == 'json') {
return $client->request($method, $url, array(), array(), array('HTTP_CONTENT_TYPE' => 'application/json'), json_encode($parameters));
} else {
return $client->request($method, $url, $parameters);
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5183 次 |
最近记录: |