|
朋友開了個(gè)淘寶店,所以經(jīng)常要將新商品及圖片發(fā)布到網(wǎng)店里,而且有時(shí)還需要上傳很多商品。如果手工一條一個(gè)商品的上傳未免太花時(shí)間,所以我就琢磨著能否用WinForm寫個(gè)程序通過WebRequest發(fā)送POST/GET請(qǐng)求來達(dá)到這個(gè)目的。由于上傳上品時(shí)即有普通的Form字段信息需要提交,還需要上傳圖片,所以在寫HttpWebRequest時(shí)參考了這個(gè)帖子http://bytes.com/topic/c-sharp/answers/268661-how-upload-file-via-c-code(How upload file via c# code?)
在淘寶網(wǎng)上發(fā)布一個(gè)商品大體分為兩個(gè)步驟(即兩個(gè)頁(yè)面,實(shí)際都是提交到同各URL進(jìn)行處理的:http://sell.taobao.com//auction/publish/publish.htm),第一個(gè)步驟為選擇商品的分類,第二個(gè)步驟為填寫商品的信息及相關(guān)照片。
通過IEInspector軟件觀察第二個(gè)步驟提交后的http請(qǐng)求的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技術(shù):嘗試通過HttpWebRequest向TAOBAO批量發(fā)布商品及上傳圖片,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。