您的位置:程序门 -> vb -> 网络编程



163相册上传问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


163相册上传问题
发表于:2007-04-20 14:20:18 楼主
我用以下代码向163相册上传图片,经抓包,发出的信息没有发送完,只发了一半,请问问题出在哪里?


private   sub   command1_click()
        me.winsock1.remotehost   =   "upload.photo.163.com "
        me.winsock1.remoteport   =   80
        me.winsock1.connect
        me.label1   =   "connecting... "
        doevents
        tmr   =   timer
        do   until   me.winsock1.state   =   7
                doevents
                if   timer   -   tmr   > =   10   then
                        msgbox   "connection   timeout. ",   vbokonly,   "error "
                        me.winsock1.close
                        exit   sub
                end   if
        loop
        me.label1   =   "ready   to   send... "
         
         
        strhttpheader   =   strhttpheader   &   "post   /appupload.do?apiname=uploadphoto   http/1.1 "   &   vbcrlf
        strhttpheader   =   strhttpheader   &   "referer:   upload.photo.163.com "   &   vbcrlf
        strhttpheader   =   strhttpheader   &   "accept:   text/* "   &   vbcrlf
        strhttpheader   =   strhttpheader   &   "content-type:   multipart/form-data;   boundary=---------------------------7d61194b027e "   &   vbcrlf
        strhttpheader   =   strhttpheader   &   "user-agent:   163upl~1 "   &   vbcrlf
        strhttpheader   =   strhttpheader   &   "host:   upload.photo.163.com "   &   vbcrlf
        strhttpheader   =   strhttpheader   &   "cookie:   ntes_sess=fxnzykyeaeepxdtlufzgdzhiazreedsvzbdejdd1xrelrfayor3ad04hbzal28fe6gy6r2jw0uhyy50l9atbmp5pr;   _ntes_nvst=1177017267156, ¦photo ¦   psessionid=ad876049f3f3404a2be7f660dae65e4d.upload-8;   netease_ssn=amdlcom;   netease_adv=11&23&1177042318041;   ntesads2781vichy=photo2782logo:97,17200,0,0,0,0,0,0&photo2782duilianb:2,35,0,nan,0,1,0,0;   _ntes_nvid=c15811bbae5405c2dca74a63d1aebd90;   _ntes_nnsit= ¦photo ¦research ¦urs ¦stock ¦   _ntes_is_survey=photo;   mail163_ssn=amdlcom;   theaddr=%u6e56%u5357;   ntesads2800lancome=photo2800logob:3,15,0,0,0,0,0,0;   hitcounter=amdlcom "   &   vbcrlf   &   vbcrlf
       
        'strhttpheader   =   strhttpheader   &   "user-agent:   mozilla/4.0   (compatible;   msie   6.0;   windows   nt   5.0;   .net   clr   1.1.4322) "   &   vbcrlf
        'strhttpheader   =   strhttpheader   &   "connection:   keep-alive "   &   vbcrlf
        'strhttpheader   =   strhttpheader   &   "cache-control:   no-cache "   &   vbcrlf
         
         
        strbody   =   strbody   &   "---------------------------7d61194b027e "   &   vbcrlf
        strbody   =   strbody   &   "content-disposition:form-data;name= " "albumid " " "   &   vbcrlf   &   vbcrlf
        'strbody   =   strbody   &   " "   &   vbcrlf
        strbody   =   strbody   &   "121357160 "   &   vbcrlf
        strbody   =   strbody   &   "---------------------------7d61194b027e "   &   vbcrlf
        strbody   =   strbody   &   "content-disposition:form-data;name= " "sid " " "   &   vbcrlf   &   vbcrlf
      '   strbody   =   strbody   &   " "   &   vbcrlf
        strbody   =   strbody   &   "tvrfm056qtbprfuwtxc9pq== "   &   vbcrlf   &   vbcrlf
        strbody   =   strbody   &   "---------------------------7d61194b027e "   &   vbcrlf
        strbody   =   strbody   &   "content-disposition:form-data;name= " "origindim " " "   &   vbcrlf   &   vbcrlf
        'strbody   =   strbody   &   " "   &   vbcrlf
        strbody   =   strbody   &   "80;80 "   &   vbcrlf
        strbody   =   strbody   &   "---------------------------7d61194b027e "   &   vbcrlf
        strbody   =   strbody   &   "content-disposition:   form-data;   name= " "originfile " ";filename= " " "   &   me.text1   &   " " " "   &   vbcrlf
        'strbody   =   strbody   &   "content-type:   application/octet-stream "   &   vbcrlf
        strbody   =   strbody   &   "content-type:   image/jpeg "   &   vbcrlf   &   vbcrlf
        'strbody   =   strbody   &   " "   &   vbcrlf
        strbody2   =   "---------------------------7d61194b027e "   &   vbcrlf
        strbody2   =   strbody2   &   "content-disposition:form-data;name= " "smallerdim " " "   &   vbcrlf   &   vbcrlf
        'strbody2   =   strbody2   &   " "   &   vbcrlf
        strbody2   =   strbody2   &   "80;80 "   &   vbcrlf
        strbody2   =   strbody2   &   "---------------------------7d61194b027e "   &   vbcrlf   &   vbcrlf
        strbody2   =   strbody2   &   "content-disposition:   form-data;   name= " "smallerfile " ";filename= " "$$_origin_$$ " "   &   vbcrlf "
        strbody2   =   strbody2   &   "content-type:   image/jpeg "   &   vbcrlf   &   vbcrlf   &   vbcrlf
        strbody2   =   strbody2   &   "---------------------------7d61194b027e-- "   &   vbcrlf   &   vbcrlf
        strhttpheader   =   strhttpheader   &   "content-length:   "   &   clng(len(strbody)   +   len(strbody2)   +   filelen(me.text1))   &   vbcrlf   &   vbcrlf
         
         
        me.winsock1.senddata   strhttpheader   &   strbody
        doevents
         
         
        me.label1   =   "sending   file   data... "
        doevents
        dim   bytbuff(8191)   as   byte
        dim   bytrem()   as   byte
        open   me.text1.text   for   binary   as   #1
                times   =   int(lof(1)   /   8192)
                redim   bytrem(lof(1)   mod   8192   -   1)
                for   i   =   1   to   times
                        get   #1,   ,   bytbuff
                        me.winsock1.senddata   bytbuff
                        doevents
                next
                get   #1,   ,   bytrem
                me.winsock1.senddata   bytrem
                doevents
        close   #1

         
         
        me.winsock1.senddata   vbcrlf   &   strbody2
        doevents
         
        me.label1   =   "file   was   sent   successfully. "
        doevents
        me.winsock1.close
         
end   sub
发表于:2007-04-21 14:06:471楼 得分:0
大概知道什么原因了,我先正常发送,抓包后把数据放到richtextbox里,

然后   winsock1.senddata   richtextbox.text  

相册那里接收到了,不过图片显示不出来,可能是richtextbox里的是串,必须要流才可以吧,

我就用了这方法

richtextbox1.text   =   抓包后的数据(文件的二进制数据之前)

winsock1.senddata   richtextbox1.text  

        dim   bytbuff(8191)   as   byte
        dim   bytrem()   as   byte
        open   me.text1.text   for   binary   as   #1
                times   =   int(lof(1)   /   8192)
                redim   bytrem(lof(1)   mod   8192   -   1)
                for   i   =   1   to   times
                        get   #1,   ,   bytbuff
                        me.winsock1.senddata   bytbuff
                        me.winsock1.senddata   vbcrlf   &   strbody2
                        doevents
                next
                get   #1,   ,   bytrem
                me.winsock1.senddata   bytrem
                me.winsock1.senddata   vbcrlf   &   strbody2
                doevents
        close   #1


richtextbox2.text   =   抓包后的数据(文件的二进制数据之后)

winsock1.senddata   richtextbox2.text  


可是,又是发到了文件二进制数据的一半时就没再发下去了

是不是winsock1不能发大的数据,那要怎么分段来发送呢?

高人请帮忙啊~~~
发表于:2007-04-21 21:27:502楼 得分:0
反复测试   winsock发送小的图片时能成功,但发送大的就丢包,不知道winsock怎么发送大文件?
发表于:2007-05-01 10:33:533楼 得分:0
应该是服务器端关闭了连接。
试试保持连接看看


快速检索

最新资讯
热门点击