我试图通过发出Post请求从erlang代码调用ejabberd(17.04)模块中的API。 API被成功调用,但请求体中的数据被截断。
以下是我发出POST请求的erlang代码。
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,[],[]),
我使用application/x-www-form-urlencoded
内容类型传递数据。
编译或运行代码时没有错误,但是,如果Body
变量中有一些特殊字符,则数据不会发送到API。
例如,当Body
变量包含以下值时:
{xmlel,<< \"加密\">>,\ 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,<< \&#34 ; JR7NorYN19NBDwyY3eqXcg == \">>}]}]},\ n {xmlel,<< \" payload \">>,[],\ n [ {xmlcdata,<< \" Da1s4qj6MiPgE1CP9S1ou5Cod // QAfmguc5GUGEk7IfTUJ8VU9CvL6iOfI3qK6Rg7uVNWACTWKBqCWGQstBkEEkwLDZHzJBq oJ6CoE4vxyfEdowWLqt84fNhGcsgvVxqmEDIln0NA2gDRd / vhGi0yIh2JdMQ55 + 6Ten1 + FVB + kwYlKxe94XyMV84Yiz + bfPkAach22oYCZyMx695JSBnaUb8MRLISlnkcpLv / UJtmEMlGER / t5Ac5BK00sbkbVo4zOMbfOgA ++ prt4mbpceTGyJpmkRa / 75xoqDPbYxG3sYujq52RguW1YO649M = \">>}]}]}
Data
变量包含以下值:
" to = 186& from = 274& body = {xmlel,<< \" encrypted \">>,\ n [{[<< \& #34; xmlns \">>,<< \" eu.siacs.conversations.axolotl \">>}],\ n [{xmlel,< < \" header \">>,\ n [{<< \" sid \">>,<< \&#34 ; 344245169 \">>}],\ n [{xmlel,<< \" key \">>,\ n [{<< \& #34;摆脱\">>,<< \" 684863397 \">>}],\ n [{xmlcdata,<< \&#34 ; MwohBTL6tSWIPtugiO0qo0RNrWFC3ypIL5JpwMN1qF8jAoQ1EAAYASIwKnIw / zo43lF4At93Q7PMePlDVGF47Hf6xIvSjm + bpcESskndwFudirxigLSqc6J / P0IEL3sErsE = \">>}]},\ N {xmlel,<< \" IV \">>,[] \ n [{xmlcdata,<< \" JR7NorYN19NBDwyY3eqXcg == \">>}]}]},\ n {xmlel,<< \" payload \& #34;>>,[],\ n [{xmlcdata,<< \" Da1s4qj6MiPgE1CP9S1ou5Cod // QAfmguc5GUGEk7IfTUJ8VU9CvL6iOfI3qK6 Rg7uVNWACTWKBqCWGQstBkEEkwLDZHzJBqoJ6CoE4vxyfEdowWLqt84fNhGcsgvVxqmEDIln0NA2gDRd / vhGi0yIh2JdMQ55 + 6Ten1 + FVB + kwYlKxe94XyMV84Yiz + bfPkAach22oYCZyMx695JSBnaUb8MRLISlnkcpLv / UJtmEMlGER / t5Ac5BK00sbkbVo4zOMbfOgA ++ prt4mbpceTGyJpmkRa / 75xoqDPbYxG3sYujq52RguW1YO649M = \">>}]}]}"
但是,当我尝试在API中获取此值时,只有以下数据可用:
{xmlel,<< \"加密\">>,\ n [{<< \" xmlns \">>, < &&; \" eu.siacs.conversations.axolotl \">>}],\ n [{xmlel,<< \" header \"> ;>,\ n [{<< \" sid \">>,<< \" 344245169 \">>}], \ n [{xmlel,<< \" key \">>,\ n [{<< \" rid \">>, << \" 684863397 \">>}],\ n [{xmlcdata,<< \" MwohBTL6tSWIPtugiO0qo0RNrWFC3ypIL5JpwMN1qF8jAoQ1EAAYASIwKnIw / zo43lF4At93Q7PMePlDVGF47Hf6xIvSjm + bpcESskndwFudirxigLSqc6J / P0IEL3sErsE
我是erlang的新手,并不确定这似乎是什么问题。任何帮助表示赞赏。