Home > Software engineering >  Unable to POST picture, bothering me for three days, can only help you a great god!
Unable to POST picture, bothering me for three days, can only help you a great god!

Time:10-03

Simulation POST upload pictures to a web site, for three days, will give up, suddenly thought of CSDN this cloud head, restart account, eight years ago, can see something, first thank you.

1. The Form - data


2. Data


3. Requeset hearder


4. Sourcecode

 Public xmlhttp_noserver1 As New MSXML2. ServerXMLHTTP 


Public Function Getbody_Post_koudai_IMG (ByVal URL, ByVal sPara)
The URL is http://v.vdian.com/wd/item/addThumbnail
'parameters'parameter sPara is d: \ \ 1 a. pg
'On the Error Resume Next


Dim strFileName
Dim arrTempFileName
ArrTempFileName=Split (sPara, "")


StrFileName=arrTempFileName (UBound (arrTempFileName))
Dim the Pre, Po
Dim fileContent
' ' ' ' ' ' 'combination string
Dim strTemp
StrTemp=""
StrTemp=strTemp & amp; "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 7 de2de2f8024e" & amp; VbCrLf
StrTemp=strTemp & amp; "The Content - the Disposition: the form - data; Name="" callback" "" & amp; VbCrLf
StrTemp=strTemp & amp; VbCrLf
StrTemp=strTemp & amp; "Imgcallback_" & amp; DateDiff (" s ", "1970-01-01 00:00:00", Now) & amp; "_" & amp; Mid (CStr (dblRnd ()), 2) & amp; VbCrLf
StrTemp=strTemp & amp; "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 7 de2de2f8024e" & amp; VbCrLf
StrTemp=strTemp & amp; "The Content - the Disposition: the form - data; Param name="" "" "& amp; VbCrLf
StrTemp=strTemp & amp; VbCrLf
StrTemp=strTemp & amp; "{" "userID ":" "" "" "* * * * *," * * * "" :" "" "" * * *} "& amp; VbCrLf
StrTemp=strTemp & amp; "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 7 de2de2f8024e" & amp; VbCrLf
StrTemp=strTemp & amp; "The Content - the Disposition: the form - data; "" name=" "imgs []; Filename="" "& amp; StrFileName & amp; "" "" & amp; VbCrLf
StrTemp=strTemp & amp; "The content-type: image/pjpeg" & amp; VbCrLf
StrTemp=strTemp & amp; "" & amp; VbCrLf
The Pre=strTemp




The fileContent=GetFile (sPara) "' details in the following



StrTemp=""
StrTemp=strTemp & amp; "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 7 de2de2f8024e --"
Po=strTemp


Dim strPost As String


Const adLongVarBinary=205
Dim rs: Set the rs=CreateObject (" ADODB. You ")
Dim lenPost As Long
LenPost=Len (Pre) + LenB (fileContent) + Len (Po)
Rs. Fields. Append "b", adLongVarBinary, Len (Pre) + LenB (fileContent) + Len (Po)

Rs. The Open
Rs. AddNew
Dim LenData
'the Convert Pre string value To a binary data
LenData=https://bbs.csdn.net/topics/Len (Pre)
Rs (" b "). AppendChunk (StringToMB (Pre) & amp; ChrB (0))
The Pre=rs (" b "). GetChunk (LenData)
Rs (" b ")=""

'the Convert Po string value To a binary data
LenData=https://bbs.csdn.net/topics/Len (Po)
Rs (" b "). AppendChunk (StringToMB (Po) & amp; ChrB (0))
Po=rs (" b "). GetChunk (LenData)
Rs (" b ")=""

FileContents' Join Pre + + Po binary data
Rs (" b "). AppendChunk (Pre)
Rs (" b "). AppendChunk (fileContent)
Rs (" b "). AppendChunk (Po)
Rs. Update
Dim FormData
FormData=https://bbs.csdn.net/topics/rs (" b ")
Rs. Close
Set the rs=Nothing


Xmlhttp_noserver1. Open the "POST", URL, False

Xmlhttp_noserver1. SetRequestHeader "Accept", "image/GIF image/jpeg image/pjpeg, image/pjpeg, application/x - the rest - flash, */*"
Xmlhttp_noserver1. SetRequestHeader "Referer", "http://v.vdian.com/vshop/1/CPC/item_do.php"
Xmlhttp_noserver1. SetRequestHeader "Accept - Language" and "useful - cn
"Xmlhttp_noserver1. SetRequestHeader "the user-agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; EmbeddedWB EmbeddedWB from 14.52: http://www.bsalsa.com/14.52)
"Xmlhttp_noserver1. SetRequestHeader "content-type," "multipart/form - data; A boundary=-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 7 de242278024e
"'xmlhttp_noserver1. SetRequestHeader "Accept - Encoding", "gzip, deflate
"Xmlhttp_noserver1. SetRequestHeader "Host", "v.vdian.com"
Xmlhttp_noserver1. SetRequestHeader "Content - Length", lenPost 'objTemp. SIZE
Xmlhttp_noserver1. SetRequestHeader "Connection", "Keep Alive -
"Xmlhttp_noserver1. SetRequestHeader "cache-control", "no - Cache"
Xmlhttp_noserver1. SetRequestHeader "Cookie", "WD_clear_domain=1; _ga=GA1.2 *; _gat=1; WD_client_rememberCountryCode=86; WD_client_tele=* * *; WD_client_country=86; WD_seller=* * *; WD_client_userid_raw=* * *; WD_client_ _raw=* * * * * *; WD_client_user_true_name=*; Seller_identity=0; W=* * *; D=*; K=* * *; U=* * *. * * *; S="* * *


Xmlhttp_noserver1. SEnd FormData

If xmlhttp_noserver1. ReadyState=4 Then


Getbody_Post_koudai_IMG=getHanzi (Bytestobstr (xmlhttp_noserver1 responseBody, "utf-8"))
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related