1
我有一个API的例子curl命令:如何翻译卷曲长命仙丹httpoison
curl -sd '{"inputs":[{"addresses": ["add42af7dd58b27e1e6ca5c4fdc01214b52d382f"]}],"outputs":[{"addresses": ["884bae20ee442a1d53a1d44b1067af42f896e541"], "value": 4200000000000000}]}' https://api.blockcypher.com/v1/eth/main/txs/new?token=YOURTOKEN
我不知道如何翻译成HTTPoison本作药剂。我一直在努力几个小时。我甚至不能开始说我都已经经历了迭代,但这里是我在哪里现在:
Connect.post("https://api.blockcypher.com/v1/eth/main/txs/new?token=#{@token}",
"",
[
{ "inputs", "{addresses, #{address_from}}"},
{ "outputs", "[{addresses, #{address_to}}, {value, #{eth_amount}}]"}
]
)
不像大多数的一切,我这实际上获得到他们的服务器尝试过,并给出了回应:
"{\"error\": \"Couldn't deserialize request: EOF\"}"
%{"error" => "Couldn't deserialize request: EOF"}
** (FunctionClauseError) no function clause matching in Base.encode16/2
(elixir) lib/base.ex:175: Base.encode16(nil, [])
(blockcypher) lib/blockcypher/handler.ex:55: Blockcypher.Handler.post_transa
ction_new/4
iex(46)>
你能帮我吗?我试图把数据放在身体部分而不是头部,但没有运气。
感谢Dogbert,可惜没有奏效。我得到一个错误,说'**(Poison.SyntaxError)意外的输入结束位置0 (毒)lib/poison/parser.ex:55:Poison.Parser.parse!/ 2 (毒)lib /毒。例如:83:Poison.decode!/ 2 (httpoison)lib/httpoison/base.ex:471:HTTPoison.Base.response/6 (blockcypher)lib/blockcypher/handler.ex:47:Blockcypher.Handler.post_transa ction_new/4' –
@Dogbert在原始请求中,'input'和'outputs [addresses + value]'都是_arrays_。我相信将地图封装成'[]'应该可以使其工作。 – mudasobwa
@mudasobwa谢谢!我用'Poison.decode!'解码了原始字符串并复制粘贴它。希望现在没有错误! @LegitStack你可以尝试我的新代码? – Dogbert