test2.erl
-module(test2).
-export([ttt/0]).
ttt()->
inets:start(),
case httpc:request(“http://www.baidu.com”) of
{ok,_Result}->
io:format(“hello ok”);
{error,_Reason}->
io:format(“hello error”)
end.
了解了用case来进行返回值不同的匹配。
test2.erl
-module(test2).
-export([ttt/0]).
ttt()->
inets:start(),
case httpc:request(“http://www.baidu.com”) of
{ok,_Result}->
io:format(“hello ok”);
{error,_Reason}->
io:format(“hello error”)
end.
了解了用case来进行返回值不同的匹配。
test1.erl
-module(test1).
-export([ttt/0]).
ttt()->
inets:start(),
R=httpc:request(“http://www.baidu.com”),
ttt(R).
ttt({ok,_Result})->
io:format(“hello ok”);
ttt({error,_Reason})->
io:format(“hello error”).
http client sample.
我开发用的是eclipse4.2安装erlide后,右键失灵,不停报空指针异常。
在eclipse3.8下也报同样的错误。
此时,只需要在eclipse中设置erl/otp的路径即可。
1、如果没有显示设置erl/opt的路径,先创建一个erlang工程,即可显示出来。
2、重启eclipse后,查看erl的runtime是否有选中默认,没有的话,手动选中。
3、创建一个module,测试erlide。
近期评论