我有一个来自api的例子curl命令:
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)>你能帮帮我吗?我试着把数据放在身体部分,而不是头,但没有运气。
发布于 2017-05-12 04:37:16
数据应该是HTTPoison.post/2的第二个参数,并且应该编码为JSON。您的数据也采用了错误的格式。
这应该是可行的:
Connect.post(
"https://api.blockcypher.com/v1/eth/main/txs/new?token=#{@token}",
"",
Poison.encode!(
%{"inputs" => [%{"addresses" => [address_from]}],
"outputs" => [%{"addresses" => [address_to],
"value" => eth_amount}]})
)https://stackoverflow.com/questions/43929102
复制相似问题