Body charset in a Post Service

Hi everyone,
I’m experiencing a very annoying problem.
I need to use a rest Service that accepts only application/x-www-form-urlencoded as content-Type
I have made a Python scriptr that works and I’m trying to replicate it with Post service node.
Though I have some troubles to find how to pass the form in the body when there are present reserved characters.
there’s the python script:

import requests

url = “

payload = {‘smiles’:“CC©CC1=CC=C(C=C1)C©C(=O)O”}
headers = {
‘origin’: “”,
‘upgrade-insecure-requests’: “1”,
‘user-agent’: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36”,
‘accept’: “text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8”,
‘referer’: “”,
‘accept-encoding’: “gzip, deflate”,
‘accept-language’: “it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7”,
‘cookie’: “_ga=GA1.2.501643331.1529332896; _gid=GA1.2.1536978171.1530717977”,
‘content-type’: “application/x-www-form-urlencoded”,
‘cache-control’: “no-cache”,
‘postman-token’: “9293e3ff-9ef9-8ac8-e179-9707df3d5fac”

response = requests.request(“POST”, url, data=payload, headers=headers)

I should pass in the body this string “smiles=CC©CC1%3DCC%3DC(C%3DC1)C©C(%3DO)O”
but somehow it doesnnt’ work. I tried different encodings nothing seems to work.
when i pass a string withoun unreserved characters (like “smiles=CC”) everything seems to be ok.
What I’m wrong?

Ok, watching the output of my topic I found part of the solution: ( C ) is interpreted like copyright symbol.
How I can overcome this trouble?

Hi @cosimotoma,

Please see here for an example how to create a POST request with application/x-www-form-urlencoded body (in the bottom “Parameter input” metanode):

This should also take care of your encoding problem via the FormEncodedHttpEntityCreator from the Palladian community extensions.

Hope that helps!


Thanks, I tried but it didn’t work, the solution i found was to use a java snippet with a script i found here in the forum
`/ system imports
import org.knime.base.node.jsnippet.expression.AbstractJSnippet;
import org.knime.base.node.jsnippet.expression.Abort;
import org.knime.base.node.jsnippet.expression.Cell;
import org.knime.base.node.jsnippet.expression.ColumnException;
import org.knime.base.node.jsnippet.expression.TypeException;
import static org.knime.base.node.jsnippet.expression.Type.*;
import java.util.Date;
import java.util.Calendar;
import org.w3c.dom.Document;

// imports for input and output fields

// Your custom imports:

import java.util.List;
import java.util.ArrayList;

// system variables
public class JSnippet extends AbstractJSnippet {
// Fields for input columns
/** Input column: “Entity” */
public InputStream c_body;

// Fields for output columns
/** Output column: “Out” */
public String out_abc;

// Your custom variables:

// expression start
public void snippet() throws TypeException, ColumnException, Abort {
// Enter your code here:
try {
URL url = new URL(“”);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();

		List<Byte> cBodArry = new ArrayList<Byte>();
		Reader r = new BufferedReader(new InputStreamReader(c_body));
		for(int c; (c = >= 0;)

		byte[] postDataBytes = new byte[cBodArry.size()];

		int i=0;
		for(byte b: cBodArry)
			postDataBytes[i++] = b;
		InputStreamReader reader = new InputStreamReader(c_body);

		conn.setRequestProperty("content-type", "application/x-www-form-urlencoded");
		conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
		BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
		out_abc = in.lines().collect(Collectors.joining(""));
	} catch (MalformedURLException e) {
	} catch (IOException e) {

// expression end

1 Like