Sending an HTTP POST request to the server via Erlang

Source: Internet
Author: User
Tags http post

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.