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.