[Erlang Study Notes] Send an http post request to the server through Erlang

Source: Internet
Author: User

Due to project testing needs, when writing a robot, I used Erlang's httpc to send a POST request to the server. I made a record myself and forgot it later.

You can see the following example:

T. erl

 
-Module (t ). -Export ([t/0]). -Define (name, "hosr "). -Define (passwd, 112233 ). T ()-> inets: Start (), SSL: Start (), Case httpc: Request (post, {"http: // 192.168.2.185: 8080/login", [], "Application/X-WWW-form-urlencoded", lists: Concat (["username =", name, "& Password =", passwd])}, [], []) of {OK, {_, _, body}-> body; {error, reason}-> IO: Format ("error cause ~ P ~ N ", [reason]) end.

The document shows how to use httpc: Request/4. If the parameters of the request method are correct, {OK, result}, result-> can be obtained.

{Status_line (), headers (), body} | {status_code (), body} | request_id ()
},

The result is
{Status_line (), headers (), body}. Therefore, only the required body is obtained. That is, Boby is the return value of the request.

It is important to note whether the returned value of the body meets the expectation. It is associated with the URL, key value, and other content submitted by the request and whether the content is handed over to the backend.

Mutual, true-> expected value; false-> [].


There may be more than one method to communicate.

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.