我正在设置一个cURL方法,而我遇到的问题是,如果cURL中有三个选项可以设置请求方法,那么我如何在每次调用时设法分别解决每个问题?这似乎有些严重的矫over过正。
我们是否需要冗余?请参阅下面的每个case语句更改冗余选项:
switch ( $method ) {
case 'POST':
curl_setopt( $this->curl, CURLOPT_POST, 1 ); // HTTP POST method
curl_setopt( $this->curl, CURLOPT_HTTPGET, false );
curl_setopt( $this->curl, CURLOPT_CUSTOMREQUEST, null );
break;
case 'GET':
curl_setopt( $this->curl, CURLOPT_POST, 0 ); // HTTP GET method
curl_setopt( $this->curl, CURLOPT_HTTPGET, true );
curl_setopt( $this->curl, CURLOPT_CUSTOMREQUEST, null );
break;
default:
curl_setopt( $this->curl, CURLOPT_POST, 0 ); // HTTP [custom] method
curl_setopt( $this->curl, CURLOPT_HTTPGET, true );
curl_setopt( $this->curl, CURLOPT_CUSTOMREQUEST, $method );
}