0

我正在使用 curl 打开一个 URL。如果适用于几个 URL。但是很少有人给我一个错误报告。当我在浏览器中打开相同的 url 时,它工作正常。浏览器和 curl 命令的输出应该是相同的,但它不是。可能是什么原因?

$ curl 'http://server:port/ABC_Service/app'
<html><head><title>VMware vFabric tc Runtime 2.6.4.RELEASE/6.0.35.A.RELEASE - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 401 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>This request requires HTTP authentication ().</u></p><HR size="1" noshade="noshade"><h3>VMware vFabric tc Runtime 2.6.4.RELEASE/6.0.35.A.RELEASE</h3></body></html>

预期输出:

$ curl 'http://server:port/ABC_Service/app'
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 

浏览器中的输出(第 1 2 行):

  <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
- <appMetadata>
4

2 回答 2

0

浏览器只是为您提供有关 XML 的交互式视图很有帮助。使用查看源代码查看实际响应。

于 2013-07-29T15:46:36.223 回答
-1

许多网站试图检测浏览器是否支持 XML/XSLT。如果用户代理是他们知道支持它的东西,他们会发送你看到的东西。如果不是,它们会发送正常的 HTML(在您的情况下,是 HTML 中的错误)。

您应该尝试设置您的用户代理:

curl -A "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5" http://server:port/ABC_Service/app

您可以在此处找到来自不同设备/程序的用户代理字符串列表

于 2013-05-31T13:57:26.567 回答