Truncated data in the POST request erlang

Viewed 95

I am trying to call an API from an ejabberd (17.04) module from erlang code by making a Post request. The API is called successfully, however, the data in the request body gets truncated.

Following is my erlang code to make the POST request.

Data = string:join(["to=", binary_to_list(To), "&from=", binary_to_list(From), "&body=", Body], ""),
Request = {binary_to_list(PostUrl), [{"Authorization", binary_to_list(Token)}], "application/x-www-form-urlencoded", Data},
httpc:request(post, Request,[],[]),

I pass the data with the application/x-www-form-urlencoded content type.

There is no error while compiling or running the code, however, if there are some special characters in the Body variable, then the data is not sent to the API.


For example, when the Body variable contains the following value:

{xmlel,<<\"encrypted\">>,\n [{<<\"xmlns\">>,<<\"eu.siacs.conversations.axolotl\">>}],\n [{xmlel,<<\"header\">>,\n [{<<\"sid\">>,<<\"344245169\">>}],\n [{xmlel,<<\"key\">>,\n [{<<\"rid\">>,<<\"684863397\">>}],\n [{xmlcdata,<<\"MwohBTL6tSWIPtugiO0qo0RNrWFC3ypIL5JpwMN1qF8jAoQ1EAAYASIwKnIw/zo43lF4At93Q7PMePlDVGF47Hf6xIvSjm+bpcESskndwFudirxigLSqc6J/P0IEL3sErsE=\">>}]},\n {xmlel,<<\"iv\">>,[],\n [{xmlcdata,<<\"JR7NorYN19NBDwyY3eqXcg==\">>}]}]},\n {xmlel,<<\"payload\">>,[],\n [{xmlcdata,<<\"Da1s4qj6MiPgE1CP9S1ou5Cod//QAfmguc5GUGEk7IfTUJ8VU9CvL6iOfI3qK6Rg7uVNWACTWKBqCWGQstBkEEkwLDZHzJBqoJ6CoE4vxyfEdowWLqt84fNhGcsgvVxqmEDIln0NA2gDRd/vhGi0yIh2JdMQ55+6Ten1+fVb+kwYlKxe94XyMV84Yiz+bfPkAach22oYCZyMx695JSBnaUb8MRLISlnkcpLv/UJtmEMlGER/t5Ac5BK00sbkbVo4zOMbfOgA++prt4mbpceTGyJpmkRa/75xoqDPbYxG3sYujq52RguW1YO649M=\">>}]}]}


The Data variable contains the following value:

"to=186&from=274&body={xmlel,<<\"encrypted\">>,\n [{<<\"xmlns\">>,<<\"eu.siacs.conversations.axolotl\">>}],\n [{xmlel,<<\"header\">>,\n [{<<\"sid\">>,<<\"344245169\">>}],\n [{xmlel,<<\"key\">>,\n [{<<\"rid\">>,<<\"684863397\">>}],\n [{xmlcdata,<<\"MwohBTL6tSWIPtugiO0qo0RNrWFC3ypIL5JpwMN1qF8jAoQ1EAAYASIwKnIw/zo43lF4At93Q7PMePlDVGF47Hf6xIvSjm+bpcESskndwFudirxigLSqc6J/P0IEL3sErsE=\">>}]},\n {xmlel,<<\"iv\">>,[],\n [{xmlcdata,<<\"JR7NorYN19NBDwyY3eqXcg==\">>}]}]},\n {xmlel,<<\"payload\">>,[],\n [{xmlcdata,<<\"Da1s4qj6MiPgE1CP9S1ou5Cod//QAfmguc5GUGEk7IfTUJ8VU9CvL6iOfI3qK6Rg7uVNWACTWKBqCWGQstBkEEkwLDZHzJBqoJ6CoE4vxyfEdowWLqt84fNhGcsgvVxqmEDIln0NA2gDRd/vhGi0yIh2JdMQ55+6Ten1+fVb+kwYlKxe94XyMV84Yiz+bfPkAach22oYCZyMx695JSBnaUb8MRLISlnkcpLv/UJtmEMlGER/t5Ac5BK00sbkbVo4zOMbfOgA++prt4mbpceTGyJpmkRa/75xoqDPbYxG3sYujq52RguW1YO649M=\">>}]}]}"


However, when I try to fetch this value in my API, only the following data is available:

{xmlel,<<\"encrypted\">>,\n [{<<\"xmlns\">>,<<\"eu.siacs.conversations.axolotl\">>}],\n [{xmlel,<<\"header\">>,\n [{<<\"sid\">>,<<\"344245169\">>}],\n [{xmlel,<<\"key\">>,\n [{<<\"rid\">>,<<\"684863397\">>}],\n [{xmlcdata,<<\"MwohBTL6tSWIPtugiO0qo0RNrWFC3ypIL5JpwMN1qF8jAoQ1EAAYASIwKnIw/zo43lF4At93Q7PMePlDVGF47Hf6xIvSjm+bpcESskndwFudirxigLSqc6J/P0IEL3sErsE


I am new to erlang and not sure of what seems to be the problem. Any help is appreciated.

0 Answers
Related