Httpc错误Erlang

时间:2015-12-05 16:35:53

标签: json http erlang cowboy

我正在使用Erlang开始开发,需要对我发送JSON并接收JSON确认的服务器进行REST HTTP调用。

遵循代码

Method = put,
URL = "http://api.teste.com:8080/v1/user_auth",
Header = [],
Type = "application/json",
Json = <<"{ \"data\" : { \"test-one\" : \"123\", \"test-two\" : \"return test 2\" } }">>,
HTTPOptions = [],
Options = [],

application:start(ssl),
application:start(inets),

httpc:request(Method, {URL, Header, Type, Json}, HTTPOptions, Options).\

运行此代码时出现以下错误:

=ERROR REPORT==== 5-Dec-2015::14:21:01 ===
Error in process <0.161.0> on node 'middleware@127.0.0.1' with exit value:
{[{reason,undef},
  {mfa,{user_account_handler,handle_post,2}},
  {stacktrace,[{httpc,request,
                      [put,
                       {"http://api.teste.com:8080/v1/user_auth",[],
                        "application/json",
                        <<"{ \"data\" : { \"test-one\" : \"123\", \"test-two\" : \"return test 2\" } }">>},
                   [],[]],
                  []},
                {cowboy_rest,call,3,[{file,"src/cowboy_rest.erl"},{line,972}]},
                {cowboy_rest,process_content_type,3,
                            [{file,"src/cowboy_rest.erl"},{line,773}]},
                {cowboy_protocol,execute,4,
                                [{file,"src/cowboy_protocol.erl"},
                                 {line,442}]}]},
  {req,[{socket,#Port<0.479>},
        {transport,ranch_tcp},
        {connection,keepalive},
        {pid,<0.161.0>},
        {method,<<"POST">>},
        {version,'HTTP/1.1'},
        {peer,{{127,0,0,1},49895}},
        {host,<<"localhost">>},
        {host_info,undefined},
        {port,8080},
        {path,<<"/v1/create_user_account">>},
        {path_info,undefined},
        {qs,<<>>},
        {qs_vals,undefined},
         {bindings,[]},
        {headers,[{<<"host">>,<<"localhost:8080">>},
                  {<<"connection">>,<<"keep-alive">>},
                  {<<"content-length">>,<<"58">>},
                  {<<"cache-control">>,<<"no-cache">>},
                  {<<"origin">>,
                   <<"chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop">>},
                  {<<"content-type">>,<<"application/json">>},
                  {<<"user-agent">>,
                   <<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36">>},
              {<<"postman-token">>,
               <<"2dc302f2-7c93-b9f9-2143-cff41bfeb45a">>},
              {<<"accept">>,<<"*/*">>},
              {<<"accept-encoding">>,<<"gzip, deflate">>},
              {<<"accept-language">>,
               <<"en-US,en;q=0.8,es;q=0.6,pt;q=0.4">>}]},
    {p_headers,[{<<"content-type">>,{<<"application">>,<<"json">>,[]}},
                {<<"if-modified-since">>,undefined},
                {<<"if-none-match">>,undefined},
                {<<"if-unmodified-since">>,undefined},
                {<<"if-match">>,undefined},
                {<<"accept">>,[{{<<"*">>,<<"*">>,[]},1000,[]}]},
                {<<"connection">>,[<<"keep-alive">>]}]},
    {cookies,undefined},
    {meta,[{media_type,{<<"application">>,<<"json">>,[]}},
           {charset,undefined}]},
    {body_state,waiting},
    {buffer,<<"{\n    \"username\":\"igor@gmail.com\"\n    , \"password\":\"123\"\n}">>},
    {multipart,undefined},
    {resp_compress,false},
    {resp_state,waiting},
    {resp_headers,[{<<"content-type">>,
                    [<<"application">>,<<"/">>,<<"json">>,<<>>]}]},
    {resp_body,<<>>},
    {onresponse,undefined}]},
  {state,undefined}],
 [{cowboy_rest,process_content_type,3,
               [{file,"src/cowboy_rest.erl"},{line,773}]},
  {cowboy_protocol,execute,4,[{file,"src/cowboy_protocol.erl"},{line,442}]}]}

0 个答案:

没有答案