最近在使用C# 抓圖片...
但是有些竟然抓不下來...
後來找到解答...
原來可能對方Server會擋..
所以必須模擬我是Firefox ..
程式碼如下:
--
/// <summary>
/// 從某網址得到那網頁的Source
/// </summary>
/// <param name="url">檔案網址</param>
/// <param name="path">儲存位置</param>
/// <returns></returns>
public void GetBytesByUrl1(string url, string path)
{
try
{
WebClient client = new WebClient();
client.Headers.Add("Accept-Language: en-us,en;q=0.5");
client.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7");
client.Headers.Add("Accept-Encoding: gzip,deflate");
client.Headers.Add("Keep-Alive: 300");
client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3");
client.DownloadFile(url, path);
}
catch (WebException ex)
{
Debug.WriteLine(ex.Message);
}
}
--
有沒有很溫馨
2008/11/13
C# 抓取圖片- Header 問題
2008/10/27
2008/10/24
C# WebService Client 設定
開發環境為 Visual Studio 2008
設定完成後會有一個 MasterService 類別,使用這個類別的 Service 就可對 WebService 的各個方法進行存取了。
MasterService.Service service = new MasterService.Service();
service.XXXWebMethod();
點選左下角的 Advanced... 按鈕
點選左下角的 Add Web References ...
輸入 URL: http://www.diija.com.tw/API/MasterService.asmx, 注意:不用加上 ?WSDL"

crossdomain 設定
須取名為 crossdomain.xml,並放在網站上的根目錄
http://www.diija.com.tw/crossdomain.xml
*.2kuso.com : wildcard 設定,www.2kuso.com, ww2.2kuso.com 都符合規則,因此會套用。
domain 可以設為 ip 格式, domain="140.119.182.100"
headers="SOAPAction", 有些瀏覽器(IE)如果沒有設 SOAPAction 會無法取得 WebService 的回傳內容。
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<!-- secure = false, means allow https access -->
<allow-access-from domain="*.2kuso.com" secure="false" />
<allow-access-from domain="*.diija.com" secure="false" />
<allow-access-from domain="*.diija.com.tw" secure="false" />
<allow-access-from domain="140.119.182.100" secure="false" />
<allow-http-request-headers-from domain="*.2kuso.com" headers="SOAPAction"/>
<allow-http-request-headers-from domain="*.diija.com" headers="SOAPAction"/>
<allow-http-request-headers-from domain="*.diija.com.tw" headers="SOAPAction"/>
<allow-http-request-headers-from domain="140.119.182.100" headers="SOAPAction"/>
</cross-domain-policy>
2008/10/23
VirtualBox NAT forword 設定
注意,在 Guest 裡 NAT 設定是 ping 不到主機的。
#CentOS-5.2 為 Guest 名稱。
如果改壞了設定,可以到 $HOME/.VirtualBox\Machines\CentOS-5.2\CentOS-5.2.xml 修改。
改完必須重新啟動 VirtualBox 才會生效。
<ExtraDataItem name="VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" value="TCP"/>
<ExtraDataItem name="VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" value="22"/>
<ExtraDataItem name="VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" value="22"/>
##pcnet/0 是掛載的第一張網路配接卡, 1 是第二張,依此類推。
## ssh 是 key
Protocol, HostPort, Guest 必須對應到同一個 key, 這個 key 可以是任何合法字串。
#SSH TCP 標定
C:\Program Files\Sun\xVM VirtualBox>
VBoxManage setextradata "CentOS-5.2" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP
#從 Host Port 22 轉到 Guest Port 22
C:\Program Files\Sun\xVM VirtualBox>
VBoxManage setextradata "CentOS-5.2" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 22
C:\Program Files\Sun\xVM VirtualBox>
VBoxManage setextradata "CentOS-5.2" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
#HTTP TCP 標定
C:\Program Files\Sun\xVM VirtualBox>
VBoxManage setextradata "CentOS-5.2" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/Protocol" TCP
#從 Host Port 22 轉到 Guest Port 22
C:\Program Files\Sun\xVM VirtualBox>
VBoxManage setextradata "CentOS-5.2" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/HostPort" 80
C:\Program Files\Sun\xVM VirtualBox>
VBoxManage setextradata "CentOS-5.2" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/GuestPort" 80


