PHP XML error 415 when send POST CURL

Refresh

November 2018

Views

225 time

2

iam using PHP CURL to send POSTFIELD but i Getting Error 415 Unsupported Media Type Here it's my code :

$data = '<?xml version="1.0" encoding="euc-kr" ?>
    <Product>
        <selMnbdNckNm>Catenzo YI 099</selMnbdNckNm>
        <selMthdCd>01</selMthdCd>
        <dispCtgrNo></dispCtgrNo>
        <prdAttrCd></prdAttrCd>
        <dispCtgrNo></dispCtgrNo>
        <prdAttrVal><prdAttrVal>
        <prdNm></prdNm>
        <prdStatCd></prdStatCd>
        <prdWght></prdWght>
        <dlvGrntYn></dlvGrntYn>
        <minorSelCnYn></minorSelCnYn>
        <suplDtyfrPrdClfCd></suplDtyfrPrdClfCd>
        <prdImage01></prdImage01>
        <prdImage02></prdImage02>
        <prdImage03></prdImage03>
        <prdImage04></prdImage04>
        <prdImage05></prdImage05>
        <htmlDetail></htmlDetail>
        <selTermUseYn></selTermUseYn>
        <selPrc></selPrc>
        <prdSelQty></prdSelQty>
        <asDetail></asDetail>
        <rtngExchDetail></rtngExchDetail>
    </Product>';
    $data = simplexml_load_string($data);

    $ch = curl_init();
    $header = array(
        "Content-Type: application/xml",
        "Accept-Charset: utf-8",
        "openapikey:myapikey",
        'Content-Length: ' . strlen($data)
    );
    curl_setopt($ch, CURLOPT_URL, "http://dev.api.elevenia.co.id/rest/prodservices/product");
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
    //curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $return=curl_exec($ch);
    echo "[MSG] Result -Xml : \n";
    echo $return;

I getting error message

HTTP/1.1 415 Unsupported Media Type Date: Wed, 03 Jan 2018 18:19:00 GMT Server: Apache Cache-Control: no-cache Cache-Control: no-store Pragma: no-cache Content-Length: 903 Expires: Thu, 01 Jan 1970 00:00:00 GMT Set-Cookie: WMONID=RgWtbnOnqnT; expires=Thu, 03-Jan-2019 18:19:00 GMT; path=/ X-Powered-By: Servlet/2.5 JSP/2.1 Vary: User-Agent Content-Type: text/html; charset=UTF-8

I hope someone can help me.

1 answers

0

Спасибо за @astrangeloop и @ frz3993 я просто небольшая ошибка с изменением $ заголовка до $ заголовков и закрытия XML-тег должен быть