2013-05-31 28 views
0

我正在使用curl來打開URL。如果爲少數網址工作。但很少有人給我一個錯誤報告。當我在瀏覽器中打開相同的網址時,它的工作正常。瀏覽器和curl命令的輸出應該是相同的,但不是。可能是什麼原因?curl命令爲URL提供不同的輸出

$ 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" ?> 

輸出(第2行):

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

響應很清楚地指出401:這個請求需要HTTP認證。您的瀏覽器必須發送憑據。 – CodeCaster

回答

-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 

您可以從不同的設備查找用戶代理字符串列表/程序here

+0

即使這個命令設置用戶代理給了相同的html錯誤輸出 – Jill448

+0

你有任何cookie /登錄信息的網頁瀏覽器呢? – hexblot

+0

不。所有的瀏覽器都關閉了 – Jill448

0

瀏覽器只是幫忙,給你的交互式視圖XML。使用查看源查看實際響應。