Code: Select all
Procedure.s GetLibID(xmlFile.s)
Protected libID.s = ""
xmlDoc = LoadXML(#PB_Any,xmlFile)
xNode = XMLNodeFromPath(RootXMLNode(xmlDoc), "plist/dict/key")
found.l = #False
thisNode = xNode
While found = #False
If GetXMLNodeName(thisNode) = "key" And GetXMLNodeText(thisNode) = "Library Persistent ID"
foundNode = NextXMLNode(thisNode)
libID = GetXMLNodeText(foundNode)
found = #True
Else
newNode = NextXMLNode(thisNode)
If newNode = 0 : End : EndIf
thisNode = 0
thisNode = newNode
EndIf
Wend
FreeXML(xmlDoc)
ProcedureReturn libID
EndProcedure
OpenConsole()
url.s = "http://snapcorp.com"
loginpwd.s = "darrick_richardson@yahoo.com:password"
SetCurrentDirectory("D:\Projects\PlayLusting\")
libid.s = GetLibID("D:\Projects\PlayLusting\iTunes Music Library.xml")
fileToUpload.s = "tall_seattle.jpg"
boundary.s = "aA7hhfk4"
origBaseEnc = AllocateMemory(Len(loginpwd))
endBaseEnc = AllocateMemory(1024)
PokeS(origBaseEnc,loginpwd,Len(loginpwd))
howMuchEnc = Base64Encoder(origBaseEnc,Len(loginpwd),endBaseEnc,1024)
actionType.s = "POST /upload_file.php HTTP/1.0" + #CRLF$
host.s = "Host: www.snapcorp.com" + #CRLF$
connecttype.s = "Keep-Alive: 300" + #CRLF$
connecttype = connecttype + "Connection: keep-alive" + #CRLF$
agent.s = "User-Agent: PlayLusting Sync 1.0" + #CRLF$ + #CRLF$
auth.s = "";"Authorization: BASIC " + PeekS(endBaseEnc,-1,#PB_Ascii) + #CRLF$
majorContentType.s = "Content-type: multipart/form-data, boundary=" + boundary + #CRLF$
majorContentLength.s = "Content-Length: <length>" + #CRLF$
submit.s = "Content-Disposition: form-data; name=" + #DOUBLEQUOTE$ + "submit" + #DOUBLEQUOTE$ + #CRLF$ + "Submit"
boundary = "--" + boundary + #CRLF$
fileUploadField.s = boundary + "Content-Disposition: form-data; name=" + #DOUBLEQUOTE$ + "file" + #DOUBLEQUOTE$ +"; filename=" + #DOUBLEQUOTE$ + fileToUpload + #DOUBLEQUOTE$ + #CRLF$
minorContentType.s = "Content-Type: image/jpeg" + #CRLF$
;transferType.s = "Content-Transfer-Encoding: binary" + #CRLF$ + #CRLF$
fileLen = FileSize(fileToUpload)
*buff = AllocateMemory(fileLen)
ReadFile(0,fileToUpload);
ReadData(0, *buff, fileLen)
finalBoundary.s = ReplaceString(boundary,#CRLF$,"--",#PB_String_NoCase,3)
requestHeader.s = actionType + host + connecttype + agent
finisher.s = #CRLF$ + boundary + submit + #CRLF$+ finalBoundary
postDataLength = Len(fileUploadField) + Len(minorContentType) + Len(#CRLF$)+fileLen + Len(finisher)
majorContentLength = ReplaceString(majorContentLength,"<length>",Str(5490))
inputData.s = requestHeader + majorContentType + majorContentLength
inputData = inputData + fileUploadField + minorContentType + #CRLF$
OpenFile(1,"temppic.jpg")
OpenFile(2,"file.dat")
sendBuffer = AllocateMemory(Len(inputData) + fileLen + 512)
PokeS(sendBuffer,inputData)
CopyMemory(*buff,sendBuffer+Len(inputData),fileLen)
WriteData(2,sendBuffer,Len(inputData) + fileLen)
CloseFile(2)
PrintN(Str(FileSize("file.dat")))
PokeS(sendBuffer + Len(inputData) + fileLen,finisher)
If InitNetwork()
conID = OpenNetworkConnection("www.snapcorp.com", 80)
If conID <> #Null
res.l = SendNetworkData(conID,sendBuffer,postDataLength)
Else
PrintN("Error: Connection could not be made" )
End
EndIf
EndIf
getLen = 1000
mem = AllocateMemory(getLen)
quit = 0
WriteConsoleData(sendBuffer,Len(inputData) + fileLen+Len(finisher))
PrintN("")
Repeat
NEvent = NetworkClientEvent(conID)
If NEvent =2
Start=1
;<- Resets timer every time Nevent=2 ->
StartTime = ElapsedMilliseconds()
Received_Lengt = ReceiveNetworkData(conID, mem, getLen)
gotit.s = PeekS(mem,Received_Lengt)
If Received_Lengt = getLen : Quit = 2 : EndIf
EndIf
Delay(300)
PrintN("Event: " + Str(NEvent))
Until Quit Or NEvent = 2
PrintN(gotit)