我目前正在尝试在 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
标题存在。