2012-08-20

https: 사용시 curl 설정 [curl setting in php when using secured http call]

헤메는 가운데서도 무언가 찾는다는 것은 의미있는 것이다. 얼마전 유료화된 Bing Search API를 사용해보려고 별짓을 다 했는데, 이제서야 답을 찾았다. 문제는 문법은 맞는데 https://로 GET 방식을 사용하다 보니 php의 보안설정이 문제가 된 것이었다.

It is meaningful when finding answers though not perfect. I was wandering to find the way to use Bing Search API which was changed as paid service using Azure server, then find way. The problem is security setting of php server when using https:// GET call.

해결방법은 http://rainmaker0303.tistory.com/83에 아주 잘 나와있다.

You can refer the solution in http://rainmaker0303.tistory.com/83.


1. 일단 APMSetup 에서 curl을 사용할 수 있게 세팅을 해 줘야 한다.

- 디렉토리 APM_Setup\Server\PHP5\ext\php_curl.dll 파일이 있는지 확인한다.
- 파일이 있다면 APM_Setup\php.ini 설정파일을 열고
- ;extension=php_curl.dll의 ;을 지워 설정에 포함시킨다.
- Apache 서버를 다시 실행하면 사용할 수 있는 세팅이 완료된다.

1. Change curl setting in php server (case when using APMSetup)

- Confirm c:\APM_Setup\Server\PHP5\ext\php_curl.dll.
- If it exists, open c:\APM_Setup\php.ini.
- Find ";extension=php_curl.dll" line then erase ; to activate this function.
- Save file and restart apache server

2. php의 file_get_contents 를 대체할 함수를 설정한다.

2. Make function to use curl in 'file_get_contents' function.

function http($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close ($ch);
return $response;
}


일단 이러고 나면 자료가 JSON 형태로 잘 받아진다. 아직 인코딩 문제가 남아있지만... (한글이나 일본어는 깨지는 듯. 따라서 JSON 데이터 전체를 읽지 못하는 문제가 있다.) 게다가 Bing Azure API는 key를 GET 방식에 숨겨서 보내기 때문에 아직도 완전한 건 아니다.

Now the response of secured call can be received as JSON format, though there is encoding problem... (Korean and Japanese are broken then the system cannot read JSON data.) Moreover, Bing Azure API has another implicit key in GET call, so need to think more^^;;

No comments:

Post a Comment