0

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: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

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.

gosseti
  • 965
  • 16
  • 40
  • Can you please show the full stack trace you are receiving when you get this error? – Justin Wood Feb 13 '17 at 18:14
  • Would you mind to share the whole error message? Also, are you sure `proxy_url` is not `false` by any chance? – Aleksei Matiushkin Feb 13 '17 at 18:14
  • I have updated the question with some more info. It seems the error is related to lack of `Host` in the headers — although it actually is there. – gosseti Feb 14 '17 at 23:33
  • Would you mind posting the real code? It would be helpful to see how get_host is being set (or called if its a function), or if you inspect the value of get_header what does it return? (i.e. is it a binary value) – The Brofessor Feb 15 '17 at 06:17
  • @TheBrofessor I have updated the above with proper with proper values in place for you. – gosseti Feb 15 '17 at 15:08

0 Answers0