POST要求をJSONオブジェクトを表す文字列で取得します。Erlang内のPOST要求のアクセス・ボディhttpd
_Env
リストは、次のようになります。サーバを起動する
[
{server_software,"inets/6.3"},
{server_name,"XTR20160414"},
{gateway_interface,"CGI/1.1"},
{server_protocol,"HTTP/1.1"},
{server_port,9000},
{request_method,"POST"},
{remote_addr,"127.0.0.1"},
{peer_cert,undefined},
{script_name,"/api/server:auth"},
{http_host,"localhost:9000"},
{http_accept,"application/json"},
{http_content_type,"application/json"},
{http_content_length,"34"},
{http_connection,"close"},
{content_length,34}
]
私のコードは次のとおりです。
http://localhost:9000/api/server:auth
:
start() ->
mnesia:start(),
inets:start(httpd, [
{modules, [
mod_alias,
mod_auth,
mod_esi,
mod_actions,
mod_cgi,
mod_dir,
mod_get,
mod_head,
mod_log,
mod_disk_log
]},
{port, 9000},
{server_name, "pokerspace"},
{server_root, "misc/log"},
{document_root, "misc/www"},
{erl_script_alias, {"/api", [server]}},
{error_log, "error.log"},
{security_log, "security.log"},
{transfer_log, "transfer.log"},
{mime_types, [
{"json", "application/json"},
{"html", "text/html"},
{"css", "text/css"},
{"js", "application/x-javascript"}
]}
]).
その後、私は内部のいくつかのデータでこのURLへのPOSTリクエストを行います
このリクエストをこのコードで処理します:
auth(SessionID, _Env, _Input) ->
mod_esi:deliver(SessionID, [
text_header(),
"authenticated"
]).
私はcontent_length
は、データが入って来ているように見えるので、適切な数に見えますこれ、34であることがわかります。今
、どのように私はそれで何かを行くためにポストされたデータを抽出していますか?
あなたはどのように/あなたがこのENVリストを得たところから上のいくつかのコードを追加していただけますか? – Dogbert
質問に追加した詳細をご覧ください。 –