プロセスの HTTP get 要求を処理する httpd を使用してモジュールを実装しようとしています。基本的に、受信した get リクエストを処理し、get パラメータを解析し、http サーバーを起動したノードで同期 gen_server メソッドを呼び出します。次に、同期呼び出しからの戻り値を含む HTML を返します。ブラウザでテストするまで、すべて正常に動作します(Chrome、Firefoxの最新バージョンが動作しています)。しかし、HTTP サーバーが指定されたパラメーターで他の URL を呼び出すことができる HTTP 転送機能を実装する必要があります。私はhttpcでそれを試しました:
httpc:request(get, {"http://localhost:55556/httpfront:get?key=1", []}, [], []).
しかし、次のエラーがスローされました:
{error,{failed_connect,[{to_address,{"localhost",55556}},
{inet,[inet],econnrefused}]}}
私を助けてくれませんか?私は何が欠けていますか?
Ps。stackoverflow.com
上記の作業など、他のサイトhttpc:request(...)
。
構成: node.erl を開始し、ノードは別のモジュールで httpfront.erl httpd デーモンを開始し、get 要求は httpfront で処理されます。私はこれを数回行います(より多くのノードを開始します)。今、ある httpfront インスタンスから httpc:request(...) を使用して別のインスタンスに接続したいと考えています。すべての HTTP ハンドラーは localhost で開始されますが、独自のポートではありません。
node.erl:
http_listener() ->
httpfront:start().
start() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
...
httpfront.erl:
start() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []),
%this is the port number, it increments on each new node
P = 55556,
% the corresponding url is: http://localhost:port/
% command are accesible this way:
% port is from 55556 until end of valid port range, increments on new node join
% http://localhost:55556/httpfront:get?key=thisisashortkey
inets: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,P},
{server_name,"httpfront"},
{server_root,"log"},
{document_root,"www"},
{erl_script_alias, {"", [httpfront]}},
{error_log, "error.log"},
{security_log, "security.log"},
{transfer_log, "transfer.log"},
{mime_types,[
{"html","text/html"}
]}
]),
io:format("OK. Good to go.~n").
get(SessionID, _Env, Input) ->
% this get() is a gen_server synchronous call on the inside
Result = node:get(Input),
mod_esi:deliver(SessionID, [
"Content-Type: text/html\r\n\r\n",
"<html><body>",
"Get<br>",
"Key=" ++ Value,
"<br>Result=" ++ Result,
"</body></html>"
]).
...
最後に、私が述べたように、他のノードからこれを呼び出そうとしましたが、エラーが発生しました:
httpc:request(get, {"http://localhost:55556/httpfront:get?key=1", []}, [], []).
{error,{failed_connect,[{to_address,{"localhost",55556}},
{inet,[inet],econnrefused}]}}
ヘルプやアドバイスをいただければ幸いです。ありがとうございました。