2026, 새로운 도약을 시작합니다.

curl 전송시 한글깨짐 문제.. 채택완료

Copy


function get_test_curl($data){



   global $g5, $config;



    $data = json_encode($data);

    $method = "POST";

    $url = 'https://받는url';

    

    $headers = array( 

        "content-type: application/json;charset=UTF-8", 

        "accept-encoding: gzip" 

    );    

    $ch = curl_init($url); 

    $timeout = 900; 

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);   

    curl_setopt($ch, CURLOPT_HEADER, 0); 

    curl_setopt($ch, CURLOPT_TIMEOUT, 30); 

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);  

    curl_setopt($ch, CURLOPT_POST, true);     

    

    $response = curl_exec($ch);

    curl_close($ch);

    return $response;

}

Copy


$body_data = array(

        "request_id" => "하나둘셋",

        "pos_type" => "과일"

    );


get_test_curl($body_data)

이렇게 데이터를 전송하는데 

받는곳에서 한글이 깨진다고 합니다

어떻게 처리를 해야할까요?

아래는 보내는데이터 입니다

답변 2개

채택된 답변
+20 포인트

전송측 서버( PHP)가 euckr은 아니겠죠?

로그인 후 평가할 수 있습니다

답변에 대한 댓글 3개

네 utf8 입니다 ^^;

https://pos.gcodesystem.com/img/KakaoTalk_20220808_145343574.png

시도 구군 등 한글로 전송한건 이미지처럼 나오는데.. 왜 그럴까요;;
정상 입니다.
단지 한글을 인코딩했을 뿐입니다.
json_encoding() 파라미터를
한번 살펴 보새요.
감사합니다
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
이렇게 해결했습니다 ~~ ^^

댓글을 작성하려면 로그인이 필요합니다.

Copy


// API POST 전송

function api_post($data, $url)

{

    $data = json_encode($data);

    //echo $data;exit;

    $headers[] = "Content-Type: application/json; charset=utf-8";

    $headers[] = "Data-Format: json";

    $curl = curl_init();

    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($curl, CURLOPT_URL, $url);

    curl_setopt($curl, CURLOPT_POST, true);

    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

    curl_setopt($curl, CURLOPT_VERBOSE, true);

    $response = curl_exec($curl);

    curl_close($curl);

    $response = json_decode($response, true);

    return $response;

}

 

$data = array(

    'compCd' => '', // 고객사코드 (*필수)

    'gprodCd' => '', // 광고제품코드 (*필수)

    'siteCd' => '', // 사이트코드 (*필수)

    'data' => array(

        'inowCd' => '', // 유입코드

        'inowUrl' => '', // 유입URL

        'accessIp' => $_SERVER['REMOTE_ADDR'], // 접근아이피

        'memo' => '', // 비고

        'name' => '', // 신청자명 (*필수)

        'hp' => '', // 신청자전화번호 (*필수)

        'gender' => '', // 신청자성별 (*필수)

        'age' => '', // 신청자나이 (*필수)

        '104' => '', // 구매목적

        '105' => '', // 상담희망시간 (*필수)

        '106' => '', // 구매동기 (*필수)

        '107' => '', // 비고

    ) // 요청데이터

);

//print_r($data);exit;

$url = "API호출 주소";

$result = api_post($data, $url); // api 전송

//print_r($result); // 결과값

이걸로 해보시고, header 부분만 추가해야하면 추가해서 해보세요.

로그인 후 평가할 수 있습니다

답변에 대한 댓글 2개

감사합니다 ~~ 적용해 보고 말씀드리겠습니다 ~~
답변이 늦었습니다 해당 소스로 변경해도 그렇다고 하네요 ;;
https://pos.gcodesystem.com/img/KakaoTalk_20220808_145343574.png

시도 구군 등 한글로 전송한건 이미지처럼 나오는데.. 이유를 모르겠습니다;;

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인
🐛 버그신고