|
朋友开了个淘宝店,所以经常要将新商品及图片发布到网店里,而且有时还需要上传很多商品。如果手工一条一个商品的上传未免太花时间,所以我就琢磨着能否用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批量发布商品及上传图片,转载需保留来源!
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。