我使用PHP CURL发送POSTFIELD但我得到错误415不支持的媒体类型 这是我的代码:
$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;
我收到错误消息
HTTP / 1.1 415不支持的媒体类型日期:星期三,03一月2018 18:19:00 GMT服务器:Apache缓存控制:无缓存缓存控制:无存储Pragma:no-cache内容长度:903到期日:1970年1月1日星期四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
我希望有人可以帮助我。
答案 0 :(得分:0)
感谢@astrangeloop和@ frz3993我将$ header更改为$ header时出现小错误,xml结束标记应为