Elixir HTTPoison no case clause matching: false error

696 Views Asked by At

I’m currently trying to build a simple HTTP service in Elixir that queries a web services (SOAP) API using HTTPoison via a proxy. This is what my code looks like:

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:[email protected]: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

However, when I run this code it returns:

no case clause matching: false

And when I check the console, I see:

[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"

I’ve verified that none of the headers or options are false. For some reason it doesn’t recognise that the Host header is present.

0

There are 0 best solutions below