2017-06-27 25 views
0

我送這個PUT http請求:http://192.168.20.7:4000/products/?id=76藥劑 - 塞 - 沒有功能語句匹配

我得到這個錯誤:

18:31:31.575 [error] #PID<0.505.0> running Api.Router terminated 
Server: 192.168.20.7:4000 (http) 
Request: PUT /products/?id=76 
** (exit) an exception was raised: 
    ** (FunctionClauseError) no function clause matching in Api.Router.do_match/4 
     (api) lib/api/router.ex:26: 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.7", method: "PUT", owner: #PID<0.505.0>, 
params: %Plug.Conn.Unfetched{aspect: :params}, path_info: ["products"], path_params: %{}, peer: {{192, 168 
, 20, 16}, 59728}, port: 4000, private: %{}, query_params: %Plug.Conn.Unfetched{aspect: :query_params}, que 
ry_string: "id=76", remote_ip: {192, 168, 20, 16}, req_cookies: %Plug.Conn.Unfetched{aspect: :cookies}, req 
_headers: [{"host", "192.168.20.7:4000"}, {"content-type", "application/json"}, {"user-agent", "vepo/1 CFNe 
twork/811.5.4 Darwin/16.6.0"}, {"connection", "keep-alive"}, {"accept", "*/*"}, {"accept-language", "en-us" 
}, {"content-length", "66"}, {"accept-encoding", "gzip, deflate"}, {"x-requested-with", "XMLHttpRequest"}], 
request_path: "/products/", 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}, "PUT", ["products"], "192.168.20.7") 
     (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.erl:442: :cowboy_ 
protocol.execute/4 

我在路由器來處理請求有這樣的:

put "/products/:id" do 
    IO.puts("putting image #{id}") 
    conn 
     |> put_resp_content_type("application/json") 
     |> send_resp(200, Poison.encode!(%{ 
      successs: "success" 
     })) 
    end 

我知道錯誤意味着我的路由器沒有處理請求。該路徑不應該用put "/products/:id"來管理那個請求嗎?

+0

請寄出'mix phoenix.routes'的輸出。 – mudasobwa

+1

另外,'put「/ products /:id」'映射到'http://192.168.20.7:4000/products/76'而不是'http://192.168.20.7:4000/products/?id=76 '。 – mudasobwa

+0

@mudasobwa我不使用鳳凰。但我想你已經指出了我的錯誤。謝謝! – user2602079

回答

3

對於未來的讀者起見:

put "/products/:id" 

被映射到:

#        ⇓⇓⇓ 
http://192.168.20.7:4000/products/76 

不會:

#         ⇓⇓⇓⇓⇓⇓ 
http://192.168.20.7:4000/products/?id=76 

後者映射到

put "/products"