Cowboy is used as the container for network requests, and the POST request for HTTP is processed. Due to the small amount of information, it took a long time to find a good solution on a foreign website. (In fact, it's just a method. I 've been reading the source code for a long time, but the English language is not very good. So I can't find the corresponding processing method. Although binary matching is used in the first place, feeling stupid ).
The following is a small example:
Hhh.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
Hhh. erl
-Module (hhh ). -behavior (cowboy_http_handler ). -Export ([init/3, handle/2, terminate/2]). % API % Init ({_ Any, HTTP}, req, [])-> {OK, req, undefined }. handle (req, state)-> % get content in POST request % username % password passwd {[{_ n, name }, {_ p, passwd}], _ REQ} = cowboy_http_req: body_qs (req), IO: Format ("name is :~ TS passwd is :~ Ts ~ N ", [name, passwd]), {OK, _ REQ} = cowboy_http_req: reply (200, [], <" OK ">, req), {OK, _ REQ, State }. terminate (_ REQ, _ state)-> OK.
Through a cowboy_http_req: body_qs (req) function, you can pass the value in the body through post and obtain the desired information through matching.
Because the format returned by this function is {list ({binary (), binary () | true}), # http_req {}}
That is, {[{"name", "name on the page" },{ "passwd", "passwd on the page"}], req1}
After obtaining the information, you can start your business with peace of mind.
Attach the code matching the binary:
<<First:1/binary,Second:1/binary,Last:2/binary>>=<<"fuck">>First=fSecond=uLast=ck
Hope to help =. =