Skip to content

Instantly share code, notes, and snippets.

@DisplayName
Created December 18, 2012 10:02
Show Gist options
  • Save DisplayName/4326785 to your computer and use it in GitHub Desktop.
Save DisplayName/4326785 to your computer and use it in GitHub Desktop.
-module(auth_test).
-export([get_default_page/0, do_auth/0]).
request(Data) ->
io:format("do login~n", []),
case httpc:request(post,
{"https://connect.garmin.com/signin",
[ ], "application/x-www-form-urlencoded", Data
},
[ {timeout, 3000} ],
[{stream, "/tmp/page.html"}, {body_format, binary}]
) of
{ok, saved_to_file} ->
io:format("Saved to file~n");
{ok, Result} ->
io:format("Received: ~p~n", [Result]);
{error, Reason} ->
io:format("Error: ~p~n", [Reason])
end.
do_auth() ->
Sep = <<"&">>,
PostRequest = [
<<"login=">>, list_to_binary("login"), Sep,
<<"login:loginUsernameField=">>, list_to_binary("test_user1"), Sep,
<<"login:password=">>, list_to_binary("test_user1"), Sep,
<<"login:signInButton=">>, list_to_binary("Sign In")
],
request(erlang:iolist_to_binary(PostRequest)).
get_default_page() ->
httpc:request("https://connect.garmin.com/calendar").
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment