0

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.

1 Answer 1

1
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'];
Sign up to request clarification or add additional context in comments.

4 Comments

yes, I missed that line when copy-paste from my editor, but I am taking the value as you mentioned, but when I execute an "echo of this" it shows me strange characters instead the xml I put in the textfield.
can you copy paste the strange characters?
These are the characters printed when I execute an echo: avoirAND00all10580date0082.122.169.2440false3.0.51tcbet30]IND
I solved the problem, sorry, I'm still very dummy in php. Thanks for your response, it helped me to find mi mistakes. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.