[j-nsp] SLAX/Curl is html-entity-encoding content

Ola Thoresen ola at nytt.no
Wed Feb 3 07:43:56 EST 2016


I am testing an op-script that is using curl to make a http-post to an 
external url.
It seems to work OK, except that the content is "html-encoded", which 
causes errors when "the other end" don't expect it.
Unfortunately I have no control over "the other end" so I can't easily 
make it understand the html-entities either.

Here is some sample code:

version 1.1;

ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
ns curl extension = "http://xml.libslax.org/curl";

import "../import/junos.xsl";


match / {
         var $url = 'http://www.example.com/foobar';
         var $query = "This is some <example> content with various 
characters: ÆØÅ #!?";
         var $params := {
                 <url> $url;
                 <method> "post";
                 <content-type> "text/plain";
                 <format> "xml";
                 <contents> $query;
         }
         var $curl = curl:open();
         var $result = curl:perform($curl, $params);

         <options> {
                 for-each(slax:break-lines( $result/raw-headers )) {
                         <output> .;
                 }
                 for-each(slax:break-lines( $result/raw-data )) {
                         <output> .;
                 }
         }
         expr curl:close($curl);
}




When this script is executed, the other end receives the http-post OK, 
but the contents has been encoded to:

"This is some <example> content with various characters: 
&#xC6;&#xD8;&#xC5; #!?"

The values of the params "content-type" and "format" does not seem to 
have any influence on the result.
If I base64-encode the content before posting it, it is not translated, 
but unfortunately the receiving end does not seem to understand the 
"Content-transfer-encoding" header, and simply parses the data as it is 
received.

Is there any way to tell the curl-library NOT to translate the content?


Rgds.

Ola Thoresen


More information about the juniper-nsp mailing list