1-Module(t).2 3-Export([test/0]). 4 5Test ()6Method =Post,7URL = "Http://192,168.124.10:3000/node/2.0/new",8Header = [],9Type = "Application/json",TenBody = "{\" name\ ": \" foo.example.com\ "}", OneHttpoptions = [], AOptions = [], - CaseHttpc:request (Method, {URL, Header, Type, Body}, Httpoptions, Options) of -{OK, {_,_,body}}-> theIo:format ("Receive Body:~p~n", [Body]), -{"id", Key} = lists:keyfind ("id", 1, Json:parse (Body)), -Io:format ("Key is:~p~n", [Key]); -{Error, reason}-> +Io:format ("Error cause ~p~n", [Reason]) - End.
The documentation lets you know how to use HTTPC:REQUEST/4. If the parameters of the request method are filled in, you can get {Ok,result}, Result---
{Status_line (), headers (), Body} | {Status_code (), Body} | REQUEST_ID ()},
The result here is {status_line (), headers (), body}, so the above is only the body needed. That is, Boby is the return value of the request.
It is important to note that the return value of the body conforms to the expectation, and is associated with the URL that the request submitted, the key value, and so on.
True-to-expected, false.
Sending an HTTP POST request to the server via Erlang