I know this is maybe a very dummy question, but I'm facing a requirement with PHP, I've made some very simple things with it, but now I really need help.
I have this scenario:
I invoke a Java Rest WS using the following url:
http://192.168.3.41:8021/com.search.ws.module.ModuleSearch/getResults/jsonp?xmlQuery=%3C?xml%20version%3D'1.0'%20encoding%3D'UTF-8'?%3E%3Cquery%20ids%3D%2216535%22%3E%3CmatchWord%3Ehave%3C/matchWord%3E%3CfullText%3E%3C![CDATA[]]%3E%3C/fullText%3E%3CquotedText%3E%3C!...
But for this I had to use a Java util class to replace some special chars in the xml parameter, because the original xml is something like:
<?xml version='1.0' encoding='UTF-8'?><query ids="16914"><matchWord>avoir</matchWord><fullText><![CDATA[]]></fullText><quotedText><![CDATA[]]></quotedText><sensitivity></sensitivity><operator>AND</operator><offsetCooc>0</offsetCooc><cooc></cooc><collection>0</collection><searchOn>all</searchOn><nbResultDisplay>10</nbResultDisplay><nbResultatsParAspect>...
Now, I've been asked to create a PHP page in which I can set the XML as input and request it to the REST WS using a submit button. I made an approach but not seems to be working, here I paste my code:
<?php
if($_POST['btnSubmit'] == "Submit")
{
$crudXmlQuery = $_POST['inputXml'];
echo $crudXmlQuery;
echo "=================================================";
$xml = str_replace("%", "%25", $crudXmlQuery);
$xml = str_replace("&", "%26", $crudXmlQuery);
$xml = str_replace("=", "%3D", $crudXmlQuery);
echo $xml;
//$ch = curl_init($url);
//curl_setopt ($ch, CURLOPT_POST, 1);
//curl_setopt ($ch, CURLOPT_POSTFIELDS,'inputXml='.$xml);
//$info = curl_exec ($ch);
//curl_close ($ch);
}
?>
<form action="sampleIndex.php" method="post">
Please insert your XML Query
<input type='text' name='inputXml' value='<?=$crudXmlQuery?>'/>
<input type='submit' name='btnSubmit' value='Submit' />
</form>
I commented the part of the cURL since it was giving me some problems, I'm not sure how to handle this requirement yet, if somebody could help me please, I will really appreciate it. Thanks in advance. Best regards.
curl_setopt ($ch, CURLOPT_POSTFIELDS,'inputXml='.$xml);
this is not going to work, you shoud url encode $xml first. (using urlencode function)
The other part - not sure what exactly not working there :) But I do not see you taking the value of input field anywhere in your code:
$crudXmlQuery = $_POST['inputXml'];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.