How to make a GET request for Cloudant from Erlang via HTTPS

I'm already fooling this topic a bit ... I can receive and send to couchdb on my local computer, but now I want to switch to using Cloudant, which requires an https connection.

I want to understand what is happening, so I would prefer to use httpc or similar at the moment, rather than, say, couchbeam, but I just can’t get into the Erlang documentation on SSL connections, and all the examples are simpler HTTP ... Cloudant There is no documentation related to Erlang.

I looked at the topic How to make an HTTPS request with Erlang , but the above example does not work for me - I get the following error report:


ฐ=ERROR REPORT==== 10-May-2011::10:40:26 ===
** Generic server <0.60.0> terminating 
** Last message in was {connect_and_send,
                           {request,#Ref<0.0.0.50>,<0.31.0>,0,https,
                               {"playground.cloudant.com",443},
                               "/",[],get,
                               {http_request_h,undefined,"keep-alive",
                                   undefined,undefined,undefined,undefined,
                                   undefined,undefined,undefined,undefined,
                                   undefined,undefined,undefined,undefined,
                                   undefined,undefined,
                                   "playground.cloudant.com",undefined,
                                   undefined,undefined,undefined,undefined,
                                   undefined,undefined,undefined,undefined,[],
                                   undefined,undefined,undefined,undefined,
                                   "0",undefined,undefined,undefined,
                                   undefined,undefined,undefined,[]},
                               {[],[]},
                               {http_options,"HTTP/1.1",infinity,true,
                                   {ossl,[{verify,0}]},
                                   undefined,false,infinity,false},
                               "https://playground.cloudant.com",[],none,[],
                               1305020425911,undefined,undefined}}
** When Server state == {state,undefined,undefined,undefined,undefined,
                            undefined,undefined,
                            {[],[]},
                            {[],[]},
                            undefined,[],nolimit,nolimit,
                            {options,
                                {undefined,[]},
                                0,2,5,120000,2,disabled,false,inet,default,
                                default,[]},
                            {timers,[],undefined},
                            httpc_manager,undefined}
** Reason for termination == 
** {{badmatch,{error,no_ssl_server}},
    [{ssl,old_connect,4},
     {httpc_handler,connect_and_send_first_request,3},
     {httpc_handler,handle_call,3},
     {gen_server,handle_msg,5},
     {proc_lib,init_p_do_apply,3}]}

and the Erlang shell is hanging ...

Here is the code I entered in the Erlang shell:


Running Erlang

Eshell V5.8.3  (abort with ^G)

1> inets:start().

ok

2> ssl:start().

ok

3>  httpc:request(head, {"https://playground.cloudant.com", []}, [{ssl,[{verify,0}]}], []).

3 :

3 > httpc: request (head, { " https://playground.cloudant.com", []}, [], []).

3 > httpc: request (get, { " https://playground.cloudant.com", []}, [{ssl, [{, 0}]}], []).

3 > httpc: request (get, { " https://playground.cloudant.com", []}, [], []).

https://playground.cloudant.com .

, , - , , , . SSL? , ? !

+3
2

. , CA, , , CA cert Erlang R15B1 . , , .

, httpc- Cloudant over HTTPS:

httpc:request
    (get, 
    {"https://" ++ username() ++ ":" ++ password() ++ "@" ++ username() ++ ".cloudant.com/_all_dbs", []}, 
    [{ssl,[{verify,0}]}], 
    []).

username() password() Cloudant.

0

:

1> ssl:start().
ok
2> whereis(ssl_sup).
<0.42.0>
3> supervisor:start_child(ssl_sup, {ssl_server, {ssl_server, start_link, []}, permanent, 2000, worker, [ssl_server]}).
{ok,<0.48.0>}
4> whereis(ssl_server).
<0.48.0>

. .

+1

All Articles