|
朋友開了個淘寶店,所以經常要將新商品及圖片發布到網店里,而且有時還需要上傳很多商品。如果手工一條一個商品的上傳未免太花時間,所以我就琢磨著能否用WinForm寫個程序通過WebRequest發送POST/GET請求來達到這個目的。由于上傳上品時即有普通的Form字段信息需要提交,還需要上傳圖片,所以在寫HttpWebRequest時參考了這個帖子http://bytes.com/topic/c-sharp/answers/268661-how-upload-file-via-c-code(How upload file via c# code?)
在淘寶網上發布一個商品大體分為兩個步驟(即兩個頁面,實際都是提交到同各URL進行處理的:http://sell.taobao.com//auction/publish/publish.htm),第一個步驟為選擇商品的分類,第二個步驟為填寫商品的信息及相關照片。
通過IEInspector軟件觀察第二個步驟提交后的http請求的RAW Stream大致為:
POST /auction/publish/publish.htm HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocume
nt, application/xaml+xml, application/x-silverlight, application/vnd.ms-excel, application
/msword, application/vnd.ms-powerpoint, */*
Referer: http://sell.taobao.com/auction/publish/publish.htm
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Content-Type: multipart/form-data; boundary=---------------------------7d9da39c0084
Accept-Encoding: gzip, deflate
Host: sell.taobao.com
Content-Length: 217424
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: po=50008882_100.0_14_0.0_%E5%8C%.; sellTbToken=%2Ceee15ee6bbaee%237856351072575161%2Ce87e3fe110be1%237856331541398694
-----------------------------7d9da39c0084
Content-Disposition: form-data; name="action"
publish/publishAction
-----------------------------7d9da39c0084
Content-Disposition: form-data; name="isMImageUser"
-----------------------------7d9da39c0084
Content-Disposition: form-data; name="_fma.pu._0.ca"
50008882
-----------------------------7d9da39c0084
Content-Disposition: form-data; name="_fma.pu._0.i"
NDczYzE0MjI3Yzc4ZTczOGI2ZGQ3ZjJiYThjMGZkYWEgYjc2MGM1MDBjYWVjYmFlN2I0MzRlZjQwZTIzOGI0NWIgMTI1NTc1MDA0NjQwNA==
-----------------------------7d9da39c0084
-----------------------------7d9da39c0084
Content-Disposition: form-data; name="_fma.pu._0.ima"; filename="DSC_6873.JPG"
Content-Type: image/pjpeg
…..
NET技術:嘗試通過HttpWebRequest向TAOBAO批量發布商品及上傳圖片,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。