Elixir HTTPoison没有case子句匹配:false error

时间:2017-02-13 17:49:00

标签: elixir phoenix-framework elixir-framework httpoison

我目前正在尝试在Elixir中构建一个简单的HTTP服务,它通过代理使用HTTPoison查询Web服务(SOAP)API。这就是我的代码:

defp body do
  """
  <?xml version="1.0" encoding="UTF-8"?>
  <soap:Envelope xmlns:xsi="http://wwww.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://wwww.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
      <ExecuteDatasetStoredProcedure>
        <securityPassword>ApiKey1234</securityPassword>
        <name>pa_sp_GetContactInfo</name>
        <parameters></parameters>
      </ExecuteDatasetStoredProcedure>
    </soap:Body>
  </soap:Envelope>
  """
end

defp headers do
  [{"Content-Type", "text/xml"},
   {"Host", "example-api.example.com"},
   {"SOAPAction", "https://example-api.example.com/Execute/Stored/Procedure"}]
end

defp options do
  [{:proxy, "http://username:password@eu-west-static-01.quotaguard.com:9293"}, 
   {:proxy_auth, {"username", "password"}}, 
   {:ssl, [{:versions, [:'tlsv1.2']}]}]
end

def show(conn, %{"email" => email}) do
  case HTTPoison.post(api_url, body, headers, options) do
    {:ok, %HTTPoison.Response{body: body}} ->
      conn |> json(%{reason: body})
    {:error, %HTTPoison.Error{reason: reason}} ->
      conn |> json(%{error: reason})
  end
end

但是,当我运行此代码时,它返回:

no case clause matching: false

当我检查控制台时,我看到:

[error] proxy error: "HTTP/1.1 400 Bad Request\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\n400 Bad Request: missing required Host header"

我已经确认没有标题或选项都是错误的。由于某种原因,它无法识别Host标题存在。

0 个答案:

没有答案