Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 尝试在chrome开发控制台中查看网络请求时Elixir后端出错_React Native_Ecto_Elixir - Fatal编程技术网

React native 尝试在chrome开发控制台中查看网络请求时Elixir后端出错

React native 尝试在chrome开发控制台中查看网络请求时Elixir后端出错,react-native,ecto,elixir,React Native,Ecto,Elixir,-我需要在react native中实现这行代码,以便在chrome开发控制台中查看我的网络请求: GLOBAL.XMLHttpRequest = GLOBAL.originalXMLHttpRequest || GLOBAL.XMLHttpRequest 但当我这样做时,我从前端发送到本地主机Elixir后端的请求会产生以下错误: 15:48:41.502 [error] #PID<0.406.0> running Api.Router terminated Server: 19

-我需要在react native中实现这行代码,以便在chrome开发控制台中查看我的网络请求:

GLOBAL.XMLHttpRequest = GLOBAL.originalXMLHttpRequest || GLOBAL.XMLHttpRequest
但当我这样做时,我从前端发送到本地主机Elixir后端的请求会产生以下错误:

15:48:41.502 [error] #PID<0.406.0> running Api.Router terminated
Server: 192.168.20.3:4000 (http)
Request: GET /favicon.ico
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in Api.Router.do_match/4
        (api) lib/api/router.ex:14: Api.Router.do_match(%Plug.Conn{adapter: {Plug.Adapters.
Cowboy.Conn, :...}, assigns: %{}, before_send: [], body_params: %Plug.Conn.Unfetched{aspect
: :body_params}, cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: false, host: "192
.168.20.3", method: "GET", owner: #PID<0.406.0>, params: %Plug.Conn.Unfetched{aspect: :para
ms}, path_info: ["favicon.ico"], path_params: %{}, peer: {{192, 168, 20, 3}, 58348}, port:
4000, private: %{}, query_params: %Plug.Conn.Unfetched{aspect: :query_params}, query_string
: "", remote_ip: {192, 168, 20, 3}, req_cookies: %Plug.Conn.Unfetched{aspect: :cookies}, re
q_headers: [{"host", "192.168.20.3:4000"}, {"connection", "keep-alive"}, {"user-agent", "Mo
zilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome
/58.0.3029.110 Safari/537.36"}, {"accept", "image/webp,image/*,*/*;q=0.8"}, {"referer", "ht
tp://192.168.20.3:4000/categories"}, {"accept-encoding", "gzip, deflate, sdch"}, {"accept-l
anguage", "en-GB,en-US;q=0.8,en;q=0.6"}, {"origin", "http://evil.com/"}], request_path: "/f
avicon.ico", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0
, private, must-revalidate"}], scheme: :http, script_name: [], secret_key_base: nil, state:
 :unset, status: nil}, "GET", ["favicon.ico"], "192.168.20.3")
        (api) lib/api/router.ex:1: Api.Router.plug_builder_call/2
        (api) lib/plug/debugger.ex:123: Api.Router.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade
/4
        (cowboy) /Users/Ben/Development/Projects/vepo/api/deps/cowboy/src/cowboy_protocol.e
rl:442: :cowboy_protocol.execute/4
现在它发生在
get”/categories/“do

问题顶行代码的主要变化是,这意味着我必须启用CORS,这是我使用浏览器插件所做的,所以Elixir可能不喜欢这样。

我补充说:

  get "/favicon.ico" do
    # Api.Repo.getCategories(conn)
  end
现在的错误是:

17:17:05.354 [error] #PID<0.370.0> running Api.Router terminated
Server: 192.168.20.3:4000 (http)
Request: OPTIONS /categories
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in Api.Router.do_match/4
        (api) lib/api/router.ex:13: Api.Router.do_match(%Plug.Conn{adapter: {Plug.Adapters.
Cowboy.Conn, :...}, assigns: %{}, before_send: [], body_params: %Plug.Conn.Unfetched{aspect
: :body_params}, cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: false, host: "192
.168.20.3", method: "OPTIONS", owner: #PID<0.370.0>, params: %Plug.Conn.Unfetched{aspect: :
params}, path_info: ["categories"], path_params: %{}, peer: {{192, 168, 20, 3}, 50258}, por
t: 4000, private: %{}, query_params: %Plug.Conn.Unfetched{aspect: :query_params}, query_str
ing: "", remote_ip: {192, 168, 20, 3}, req_cookies: %Plug.Conn.Unfetched{aspect: :cookies},
 req_headers: [{"host", "192.168.20.3:4000"}, {"connection", "keep-alive"}, {"access-contro
l-request-method", "GET"}, {"origin", "http://evil.com/"}, {"user-agent", "Mozilla/5.0 (Mac
intosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110
 Safari/537.36"}, {"access-control-request-headers", "x-requested-with"}, {"accept", "*/*"}
, {"referer", "http://localhost:8081/debugger-ui"}, {"accept-encoding", "gzip, deflate, sdc
h"}, {"accept-language", "en-GB,en-US;q=0.8,en;q=0.6"}], request_path: "/categories", resp_
body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-re
validate"}], scheme: :http, script_name: [], secret_key_base: nil, state: :unset, status: n
il}, "OPTIONS", ["categories"], "192.168.20.3")
        (api) lib/api/router.ex:1: Api.Router.plug_builder_call/2
        (api) lib/plug/debugger.ex:123: Api.Router.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade
/4
        (cowboy) /Users/Ben/Development/Projects/vepo/api/deps/cowboy/src/cowboy_protocol.e
rl:442: :cowboy_protocol.execute/4
17:17:05.354[错误]#正在运行Api的PID。路由器已终止
服务器:192.168.20.3:4000(http)
请求:选项/类别
**(退出)引发了一个异常:
**(FunctionClauseError)Api.Router.do_match/4中没有匹配的函数子句
(api)lib/api/router.ex:13:api.router.do_match(%Plug.Conn{adapter:{Plug.Adapters。
Cowboy.Conn,:…},赋值:%{},在发送之前:[],body参数:%Plug.Conn.Unfetched{aspect
::body_params},cookies:%Plug.Conn.Unfetched{aspect::cookies},暂停:false,主机:192
.168.20.3”,方法:“选项”,所有者:#PID,参数:%Plug.Conn.Unfetched{aspect::
params},path_info:[“categories”],path_params:%{},peer:{{192,168,20,3},50258},por
t:4000,私有:%{},查询参数:%Plug.Conn.Unfetched{aspect::query\u params},查询参数
ing:,远程ip:{192,168,20,3},请求cookies:%Plug.Conn.Unfetched{aspect::cookies},
请求头:[{“主机”,“192.168.20.3:4000”},{“连接”,“保持活动”},{“访问控制”
l-request-method“,”GET“},{”origin“,”http://evil.com/“},{”用户代理“,”Mozilla/5.0(Mac
intosh;英特尔Mac OS X 10_12_4)AppleWebKit/537.36(KHTML,类似Gecko)Chrome/58.0.3029.110
Safari/537.36“},{”访问控制请求头“,”x-request-with“},{”accept“,“*/*”}
,{“referer”http://localhost:8081/debugger-ui“},{”接受编码“,”gzip,deflate,sdc
h“},{“接受语言”,“en GB,en US;q=0.8,en;q=0.6”}],请求路径:“/categories”,分别为_
正文:nil,resp_cookies:%{},resp_头:[{“缓存控制”,“最大年龄=0,私有,必须重新设置”
验证“}],方案::http,脚本名称:[],密钥基:nil,状态::unset,状态:n
il},“选项”,“类别”,“192.168.20.3”)
(api)lib/api/router.ex:1:api.router.plug\u builder\u call/2
(api)lib/plug/debugger.ex:123:api.Router.call/2
(plug)lib/plug/adapters/cowboy/handler.ex:15:plug.adapters.cowboy.handler.upgrade
/4
(牛仔)/Users/Ben/Development/Projects/vepo/api/deps/cowboy/src/cowboy_protocol.e
rl:442::cowboy_protocol.execute/4
这个错误也一再出现:

17:16:48.032 [error] GenServer #PID<0.332.0> terminating
** (stop) exited in: GenServer.call(Postgrex.TypeManager, {:get, Ecto.Adapters.Postgres.Typ
eModule, {'localhost', 5432, "api_repo"}}, 5000)
    ** (EXIT) time out
    (elixir) lib/gen_server.ex:737: GenServer.call/3
    (postgrex) lib/postgrex/protocol.ex:621: Postgrex.Protocol.bootstrap/3
    (postgrex) lib/postgrex/protocol.ex:475: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:134: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

17:16:48.032 [error] GenServer #PID<0.329.0> terminating
** (stop) exited in: GenServer.call(Postgrex.TypeManager, {:get, Ecto.Adapters.Postgres.Typ
eModule, {'localhost', 5432, "api_repo"}}, 5000)
    ** (EXIT) time out
    (elixir) lib/gen_server.ex:737: GenServer.call/3
    (postgrex) lib/postgrex/protocol.ex:621: Postgrex.Protocol.bootstrap/3
    (postgrex) lib/postgrex/protocol.ex:475: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:134: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
17:16:48.032[错误]GenServer#PID终止
**(停止)退出:GenServer.call(Postgrex.TypeManager,{:get,exto.Adapters.Postgres.Typ
eModule,{'localhost',5432,“api_repo}},5000)
**(退出)超时
(elixir)lib/gen_server.ex:737:GenServer.call/3
(postgrex)lib/postgrex/protocol.ex:621:postgrex.protocol.bootstrap/3
(postgrex)lib/postgrex/protocol.ex:475:postgrex.protocol.handshake/2
(db_connection)lib/db_connection/connection.ex:134:DBConnection.connection.connect/2
(connection)lib/connection.ex:622:connection.enter_connect/5
(stdlib)proc_lib.erl:247::proc_lib.init_p_do_apply/3
最后信息:无
国家:Postgrex.协议
17:16:48.032[错误]发电机服务器#PID终止
**(停止)退出:GenServer.call(Postgrex.TypeManager,{:get,exto.Adapters.Postgres.Typ
eModule,{'localhost',5432,“api_repo}},5000)
**(退出)超时
(elixir)lib/gen_server.ex:737:GenServer.call/3
(postgrex)lib/postgrex/protocol.ex:621:postgrex.protocol.bootstrap/3
(postgrex)lib/postgrex/protocol.ex:475:postgrex.protocol.handshake/2
(db_connection)lib/db_connection/connection.ex:134:DBConnection.connection.connect/2
(connection)lib/connection.ex:622:connection.enter_connect/5
(stdlib)proc_lib.erl:247::proc_lib.init_p_do_apply/3
最后信息:无
国家:Postgrex.协议

该错误是由于请求
/favicon.ico
。您可以忽略它,或者添加一个提供服务的
get”/favicon.ico“
,或者将一个
favicon.ico
图标文件放到web根目录中。@Dogbert谢谢!该错误并不严重,但有一个严重错误,因为它不再获取类别。我在问题的底部贴了一个(希望)更有用的错误。@Dogbert并在问题的底部贴了另一个错误question@Dogbert我刚刚将
options”/categories/“do Api.Repo.getCategories(conn)end
添加到
router.ex
中,现在它可以工作了。干杯
17:16:48.032 [error] GenServer #PID<0.332.0> terminating
** (stop) exited in: GenServer.call(Postgrex.TypeManager, {:get, Ecto.Adapters.Postgres.Typ
eModule, {'localhost', 5432, "api_repo"}}, 5000)
    ** (EXIT) time out
    (elixir) lib/gen_server.ex:737: GenServer.call/3
    (postgrex) lib/postgrex/protocol.ex:621: Postgrex.Protocol.bootstrap/3
    (postgrex) lib/postgrex/protocol.ex:475: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:134: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

17:16:48.032 [error] GenServer #PID<0.329.0> terminating
** (stop) exited in: GenServer.call(Postgrex.TypeManager, {:get, Ecto.Adapters.Postgres.Typ
eModule, {'localhost', 5432, "api_repo"}}, 5000)
    ** (EXIT) time out
    (elixir) lib/gen_server.ex:737: GenServer.call/3
    (postgrex) lib/postgrex/protocol.ex:621: Postgrex.Protocol.bootstrap/3
    (postgrex) lib/postgrex/protocol.ex:475: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:134: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol