Pact>> Pact Provider主机不是localhost

时间:2017-02-23 07:48:30

标签: provider pact

我正在使用pact java>当提供者主机是localhost时,Pact验证工作。 我如何提供其他主机详细信息? 当我指定这样的提供者时,

<serviceProvider>
   <name>provider1</name>
   <protocol>http</protocol>
   **<host>**google.com**</host>**
   <path>/</path>

   <consumers>
    <consumer>
    <name>consumer1</name>
    <pactFile>../pacts/test_consumer-test_provider.json</pactFile>
    </consumer>
    </consumers>
</serviceProvider>

我收到回复

Verifying a pact between consumer1 and provider1
  [Using file ../pacts/test_consumer-test_provider.json]
  Given test state
         WARNING: State Change ignored as there is no stateChange URL
  Invalid Information Model
      Request Failed - google.com

如何提供其他主机详细信息?

2 个答案:

答案 0 :(得分:4)

google.com不是有效的主机,而是Google的基本域名。您应该提供实际的主机名来发送请求。

例如,使用curl到google.com

$ curl -v http://google.com
* Rebuilt URL to: http://google.com/
*   Trying 216.58.203.110...
* Connected to google.com (216.58.203.110) port 80 (#0)
> GET / HTTP/1.1
> Host: google.com
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 302 Found
< Cache-Control: private
< Content-Type: text/html; charset=UTF-8
< Referrer-Policy: no-referrer
< Location: http://www.google.com.au/?gfe_rd=cr&ei=ckz9WMKPDYTr8weL36iABA
< Content-Length: 262
< Date: Mon, 24 Apr 2017 00:53:06 GMT
< 
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.com.au/?gfe_rd=cr&amp;ei=ckz9WMKPDYTr8weL36iABA">here</A>.
</BODY></HTML>

返回302 Moved回复。

如果在启用调试日志记录的情况下运行(maven的-X参数),您应该获得更多详细信息,以便验证者将请求视为失败。

答案 1 :(得分:0)

主机是提供商的IP或主机名地址。因此,如果您的提供商可以说部署了某个地方,则必须提供该部署的IP地址。您不能随便随机提供HOSTNAMEs作为google.com。