Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- variables
- string
- Ajax
- date
- php
- Laravel
- Linux
- composer-php
- 웹하드추천
- Forms
- curl
- function
- Arrays
- HTML
- file-upload
- UTF-8
- Regex
- 전략
- OOP
- 경영
- post
- 무료다운로드쿠폰
- Session
- 웹하드순위
- MySQL
- jquery
- Apache
- JSON
- JavaScript
Archives
- Today
- Total
개발! 딱 깔끔하고 센스있게!
PHP cURL options CURLOPTuHEADER, CURLOPTuRETURNTRNTRANSFER 충돌인가요? 본문
개발 스크랩 메모/PHP
PHP cURL options CURLOPTuHEADER, CURLOPTuRETURNTRNTRANSFER 충돌인가요?
렉사이 2020. 12. 23. 22:36나는 CURL과 Php을 사용하여 API 인증을 하고 있다.
이렇게:
$ch = curl_init(); $headers = []; $headers[] = 'Content-Type: application/json'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_URL, $this->url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $this->body )); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $this->response = json_decode( curl_exec($ch) ); curl_close ($ch);
응답을 요청하는 주체는 상태 코드를 포함하고 성공을 요청하면 사용자 대상입니다.
이것은 익명 요청이 있어서, 호응의 영패로 되돌아가는 것이다.
내 질문:스크립트의 상술한 응답이 비어 있습니다.
내가 CURLOPT RETURNTRNSFER 선택을 주석한다면 내가 필요한 것을 얻었지만 호응을 받았다는 것은 1이다.
제가 CURLOPTu HEADER 옵션을 주석하면 호응하는 주체만 받습니다.
http 과 https 사이 전환을 시도해봤습니다.
PHP-5.5.27을 사용하고 있습니다.
대답
너는 맹목적으로 코드를 해명하지만 네가 얻은 것은 JSON 이다.
요컨대: 아니야.제목을 포함한 텍스트인데, 뒤에 JSON 이 있을 수도 있다.
비슷한 일을 하다.
$ch = curl_init(); $headers = []; $headers[] = 'Content-Type: application/json'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_URL, $this->url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $this->body )); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); $info = curl_getinfo($ch); $actualResponseHeaders = (isset($info["header_size"]))?substr($response,0,$info["header_size"]):""; $actualResponse = (isset($info["header_size"]))?substr($response,$info["header_size"]):""; $this->response = json_decode( $actualResponse ); curl_close ($ch);
'개발 스크랩 메모 > PHP' 카테고리의 다른 글
PHP 폼 제출 (0) | 2020.12.23 |
---|---|
밀집형 PHP 스크립트 실패 w / 지정한 시간 초과 'error/ apulength u filter (0) | 2020.12.23 |
php 속의 완벽한 Soap (Wsdl) web 서비스 [닫기] (0) | 2020.12.23 |
PHP 날짜 기본 시간대 설정 () (0) | 2020.12.23 |
Symfony 의 최적 코스 (Windows 에서 PHP) 를 실행합니다. (0) | 2020.12.23 |
Comments