Created
March 8, 2012 10:08
-
-
Save jnaskali/2000102 to your computer and use it in GitHub Desktop.
PHP: Send XML over POST with cURL and save response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sendXmlOverPost($url, $xml) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
// For xml, change the content-type. | |
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // ask for results to be returned | |
// Send to remote and return data to caller. | |
$result = curl_exec($ch); | |
curl_close($ch); | |
return $result; | |
} |
It works!. Thank you.
Thank you! if you post to a https address, you put this another line:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
@ZaeakiLacelot, please do not tell people to add the following to any code in a production environment:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
It can be okay in a development environment, but it creates the possibility of a MitM attack. Instead, if you are experiencing issues, load the certificate chain for the site that you are connecting to.
i tried to send xml request within curl return this response
notice : response must be xml
any help please
b"""
\x1Fï\x08\x00\x00\x00\x00\x00\x04\x00Ý¢\x07`\x1CIû%&/m╩{\x7FJ§JÎÓtí\x08Ç`\x13$ÏÉ@\x10ý┴ê═µÆý\x1DiG#)½*ü╩eVe]f\x16@╠ÝØ╝¸Ì{´¢¸Ì{´¢¸║;ØN'¸▀ ?\fd\x01l÷╬J┌╔×!Ǭ╚\x1F?~|\x1F?"\x1E \x1E´\x16ezÖÎMQ-?¹hw╝¾QÜ/ºı¼X^|÷Ð║=▀>°Þ¸8z▄T┘ÛÐÚ‗2/½U×Ê+╦µ\x11>¹ýúy█«\x1E¦¢█Lþ¨"kã¶\x15>\x1FW§┼]³r7Îù¯~ñ»¢k
¹Íııı°Û\x1E7Ì█┘┘¢¹{\x7F±³5\x03┌.ûMø-º╣{kv¾[\x1F)óO¬┘§ÐÒoWm^>/Ü÷U̼¬eúx\x07`~z¢,Vy=╬ø╗W¨ñ╔Ù╦bÜ\x03Ûâ╗\x1F¨\x10^º_ıÑ}ôÓl»│v<®¬ÀDº|yQ,sé±Q·ªXõ»█lAä┘█┘█┘Ì┘¦Ì²¶═¯╬ú¦\x07Å÷\x1Eîw>¢ `wþÌ';╗Åvêðg╦÷ñÜÕƒ}t¦W┐Î├ÔÕ│ç\x07'mq´╦ƒ(Û¦Ú├´³─¯³'┐S]ƒ-¥Xƒ\x7F^}þ═½ƒ:9²}>¾±Ê_Sü‗Øù;╗\x0F¸÷v?J┐Ø5»»ùı‗zA├=¤╩&ºÀ^dï³Þ©L_dWuÍñ‗µ±*½█E¥løÃw╣┴Ò╗³E\x0F‗̺¹¹o:É█zÝ\x03~Øò┘Bߥ^\x17m~\x03╠â\x07\x0Fw\x1Eýt`åÏÍ?Øe╦trØ¥¬ê\x1D▓¶ÚzÆ\x15Ú\x17¨¼╚Êôó¢Ì▄┴¢Øç¹;¸7vðL½ÂM_f§█¶eÖMsÚa3Ï\x07\x0F¸¯\x1F\x1Ct└\x06┤`\¨Ñ═É÷÷v\x1Eé\x11\x02H\x01éO¬ÕÆX¼¡ûÚwÍï╝¿│y·<{ø7ÚøÛèñv3³ç\x0F\x0F÷¸>Ý└¸1}▓«\x7F:Ñ®;«│ëÝ`3LÔ▒¦ÌÞC£»'eÑ\fÂ\x19ͯ┴■⢯°}³N▓UÐVÕ¡`¦▀ t´A\x07VÇÎ╔±½þo¥|æ>²‗╗/Ìð Ëo\x7F¨µ¶¨f¿ƒ¯?xpð┼0äZ┤\x19iKÜæ/‗«Ê\x13\x12ª:+o┼Hƒ¯▀█¦\f╝ZÍ┘ý6░\x1E>Ï▀¢\x01V]]-s░¨\x0Fî mº¤‗ª-.\t¦øÑi¸■º╗╗]f║íç\e ¯?Ï?Þ╩gÙM ËÒ/ÄOÊ/▓ó!■?!í*˃,‗½µ\x06░¸¸\x1Eý\x1C▄\x1AlÁ«Ë´d5═ßf░{¸\x1E|z\x7F#ÏlæMÏ7¾<²╔ÛbØo\x06║¹É`nÈÏ2Sd*‗zÖÁdÑ│[ë├├{\x07\x07¹\e¨aÂnè÷Ú^·6_■ Ø▀\fæì╦Ì&êº\vR\x1Fñ÷ˤÙl9\x13,ooa\x1E<Ï┐¸░\x03Ì'o\f·M w\x1E<ý╬X\x1Cc2┌u▀&Ìåëw>¦┘Ý┘\\x1F´gYQ/¬e{\e`\x07{╗¸÷╗4\x0EÇ\x15uËZ\x1D#/▀ãÍÆ¿}┌ôëÇ\x14¤¥|§µ½\x17ºÚ╔¾Òλ¤ND9ªÃ/Å_¢¨Ô¶┼øÎøß├*<▄▀\x08ƒ£Ä╝VdoEï{\x07;¸╗┤\x08@~>¤«│█│├├¦{ñ$7\x02dPO‗▓$ß]þ]~Ï\f~þ■º\x07¸6Æ@└\x7FQ╠«HÙªº´Vu̶Öns/{;¸¯=Þ\x0Eó§8─tBc Îa¢©®¸¯?°¶`#®┐ØM┌¬¬╔Séù4Jƒ Ì»\x04±&²àõ¯\x1EªõdW§M╚´Éc¢¹jc?E\t_çqåcb·¢┘<Ý|z´ß¢Mãõ█UY╠▓Ù¶l╣┤┤▀NE▒µÝmz ½▓█ÑÊM=╚HnÙ[}║w»gbB·\fvq\È+Üü═\x1DÉï┤s┐½doÎ┴÷Ùý<cOys\x17;\x07\x0F\x0E6╗\tÊ■©^d│,}R«¾'┘§fÿ¹{¹¶t`åöG¾bR4Úùõü¿~▄\ftþß⹸¯uÇF\x10e¿»█Ù\x12j½╬.ê=┐ Y\x15¬l¯Ôß╬■¯¢.ÃD║x]Ø\x17°)3¨ö╝¿û■┐\x19÷ââ{╗\x0F6‗JÇ8CV.▄\fÿ³╝¢\x1Eø\x07Ǥ\x00°╗U]╬Ê7õ×*¢5v║ì&ª\x00¹Ó`ô¼▓Tƾ█Æc¢l3CÖ¸V\x1FÉÒ■á█E0
%ååûøí¦█┐┐À█ò\e\x1Fa#▀ðY?æ5§fp;¸w¸\x1Evcò(©'y6Ø▀åñ\x0F?}°ÓËMv┴é<®¾³mS╠È╝m\x06{o S
Ên\x03Í║R\x12ÿÌ\x06°├\x07;{¸w:└├9·.d¡.\x10ñË/┐h]\x18{╔\f▒\x19³╬¯┴º¸^m\x02 \x1Cße6R¯énkRX¤Wb╠FÚ±║¡.ÛlET½╚áNß\x7F▀ðÚâH└Þ\x13ýy×~±Å■ıu1+rcþ\x04┬/╠`GëÚ¤¾ÜRpF¬nÞij«²M£$╣\x12(E~±\x06h¸\x1F÷\x13&}hÀæ\x18J\x18¦█lÛ┐╚ÙÚ║¯9YFW=!ç|×Ñ▀╬ïï9}©╣7bñØØM▄¤▒¨èl\ea~{\x0E:Ï┘█{ðÕ■p\x10à§│È\x00▀\x1E:"×¢.¶\x00i\x07\bÛ[â&Ò░¸`úm¹Ô\x1F²;.¾Õ¬ÿ¥U¿VÉoƒ^┌█\x7F©┐ÀÐ\x04y¢£Mû4ºm╗n╔e'Eq¹┴\x1CP$█Ò±áø\x17YË\x14ïLÉV└Äí6C▀┘%═¨ØMð_ͨó ©pë\x18¦`,_dÕREÖ®\x07¸╗RuS\x0FK?Ì\x0FXksgP\x08\x0F6║_²╬^\x17e1%Àµ╦¼1·us'╗¸Hqw═aÏ╔║,\x17ÖÚÓkͯ²{\x0F{]┤×p╝╩Ï\x7Fñ▄w»ù│9e×M/ø\x01\x13üH5u\x00\x07©\x13õ<'%Î▄Jg¯}·Ú¯µ░´UExÆ_dì5ì═ðv¸´´o¶\f\f░/ÍuU²¶f`¸¯Ý=|©y¿Ç÷ñZÀ┼/óp¸'I▀d═fÿ\x0F(å¯àY\x1DÿD©W┘§<H¦oåèÕàO_oåzÖºo<os3└â¦âç=Ö¾Ú°z×-/Ûb¹¨{hı¹\x0F\x1F¯o┤Ý»ï\vÆY\x18Á]à·&ƒVï═P\x0F÷ëñ\x07\eá¥╔~·6ÏQ2¨ËØ«▀\x1E└íöõÀo\x03ë┬¶¢ç_▄\x00Úï³z÷>Âto´Ì┴µ³<á¥*┌\x1Flƒd5▓\x00#\x01øå║Y▒ñà┴é~╗\x1F@┌\x1Fvº,ý§ýï˶õı´¾·═±¾»æ¶·tôÄbÏOÎX\x1CÉ7ØQÔ@a¦P▓°ã>÷¯w=ø■\x00$ÙÒy\tøí‗b╔═d¨23Ì┴/dþ¶6ÖãâO\x1F\x12 l\x04-\x01┬m¶┬Ì̺¶▀F`u¥ZY>³à\x1EÜÚôÙ¶Y÷v^»g7µ÷)µ¦yÏÁÜ¡?ôWU·:¤(│oªR║r\x13║╣âØç\x07;¹]}\x14\fõ'\x15.¾³(=YSÈô║¿\x03ÜTÆcø;:©┐{owú╬g-o¿┐\x11ÍCÊK¢ö|\x00Ù▓ÜVÀ\x11■\x07¸v\x1FÌ´Ê7ǶS┼OTòÆ└\x12Á\vT~╩╩À¹²ıÙÓ/]ݺ¤Ü*[=zR═«═´º╦╦╝¼V¨Ð \x03ÃáòO¸ \x00\x00
"""
I'm getting an "Array to string conversion" error for line 9. I'm sure it's a good xml file though.
What can I do to debug this?
Thanks for any help.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this function. It works like a charm!