Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP General (http://www.velocityreviews.com/forums/f65-asp-general.html)
-   -   Urgent Deliverable (http://www.velocityreviews.com/forums/t800340-urgent-deliverable.html)

kalikoi@gmail.com 01-02-2006 04:34 AM

Urgent Deliverable
 
Hi All

when i execute the following code i'm getting the error

************************************************** **************************
Content-type: text/html
Software error:
Malformed multipart POST
************************************************** ***************************


<%
dim strDownloadedCode1
Class MultiPartFormPost
Public Boundary
Private NewData
Private PreviousData
Private ItemString
Private blnLastItem
dim http
'The next two functions build up a string of form elements and files to
add
'to the form post.
Public Sub AddFile(LocalPath,FieldName)
ItemString = ItemString & "FILE^^" & LocalPath & "^^" & FieldName &
"||"
End Sub
Public Sub AddField(FieldName,FieldValue)
ItemString = ItemString & "FIELD^^" & FieldName & "^^" & FieldValue &
"||"
End Sub
Public Function Send(URL)
If Boundary = "" then Boundary =
"http://SERVER2(DESTINATION)/XXXimport/code/upload.cgi-MultipartFormPost"
'Default Boundary
'Remove the last divider element
ItemString = left(itemstring,len(itemstring) - 2)
'Create an array of the various form elements to post
Items = Split(ItemString,"||")
For count = 0 to ubound(Items)
'Preserve the Current Binary Data
PreviousData = NewData
'Grab the data needed to post each form element
ItemPart = Split(Items(Count),"^^")
'Are we dealing with the last element?
If count = UBound(Items) Then blnLastItem = True
If ItemPart(0) = "FILE" Then
AddItem 0,ItemPart(1),ItemPart(2) 'Add File
else
AddItem 1,ItemPart(1),ItemPart(2) 'Add Field
end if
Next
'Create HTTP object to Post the data
Set http = CreateObject("MSXML2.ServerXMLHTTP")
http.Open "POST", URL, False

http.setRequestHeader "Content-Type", "multipart/form-data; boundary="
+ Boundary
'Send the Data, and grab the response.

http.send NewData
If http.readyState <> 4 then
http.waitForResponse 10
End If
strDownloadedCode1 = http.responseText
set http = Nothing

End Function
Private Sub AddItem(FType,arg1, arg2)
If FType = 1 then 'Add field
NewData = BuildFormData(arg1, arg2,"")
else 'Add file
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Does the file exist?
if Not objFSO.FileExists(arg1) then Exit Sub
'Grab the file data as binary.
Set Stream = CreateObject("ADODB.Stream")
Stream.Type = 1 : Stream.Open : Stream.LoadFromFile arg1
FileContents = stream.read
'Build this elements RAW HTTP Data
NewData = BuildFormData(FileContents, arg1, arg2)
'Clear up!
stream.close : set stream = nothing : Set FSO = Nothing
end if
End Sub
Private Function BuildFormData(arg1, arg2, arg3)
'Have any items been added yet?
If lenb(PreviousData) > 0 then
pre = vbCrLf
else
pre = ""
end if
'Arg3 will be blank if dealing with a Field Element
If arg3 <> "" then 'File Element
'Set the Element's preceding HTTP String
Pre = Pre & Boundary & vbCrLf & "Content-Disposition: form-data; " & _
"name=""" & arg3 & """; filename=""" & arg2 & """" & vbCrLf & _
"Content-Type: application/upload" & vbCrLf & vbCrLf
else 'Field Element
'Set the Element's preceding HTTP String
Pre = Pre & Boundary & vbCrLf & "Content-Disposition: form-data; " & _
"name=""" & arg1 & """" & vbcrlf & vbcrlf
end if
'Are we dealing with the last element?
If blnLastItem then
'Set the last element's finishing HTTP String
Po = vbcrlf & Boundary + "--" + vbCrLf
else
Po = ""
end if
'Create a recordset instance so we can manipulate binary data
Set RS = CreateObject("ADODB.Recordset")
If arg3 <> "" then 'File Element
RS.Fields.Append "b", 205, Len(Pre) + LenB(arg1) + Len(Po)
else 'Field Element
RS.Fields.Append "b", 205, Len(Pre) + Len(arg2) + Len(Po)
end if
RS.Open : RS.AddNew 'Create a record within the recordset object
LenData = Len(Pre)
'Convert the preceeding HTTP String to binary
RS("b").AppendChunk (StringToMB(Pre) & ChrB(0))
Pre = RS("b").GetChunk(LenData) : RS("b") = ""
If blnLastItem then ' Last element?
'Convert the last element's finishing HTTP String to binary
LenData = Len(Po) : RS("b").AppendChunk (StringToMB(Po) & ChrB(0))
Po = RS("b").GetChunk(LenData) : RS("b") = ""
end if
if arg3 = "" then 'Convert Field's Value to binary.
LenData = Len(arg2) : RS("b").AppendChunk (StringToMB(arg2) & ChrB(0))
arg2 = RS("b").GetChunk(LenData) : RS("b") = ""
end if
'If there was already Binary Data (form elements), then we add this in
front
'of this element's binary data
If LenB(PreviousData) > 0 then RS("b").AppendChunk (PreviousData)
'Add the preceding HTTP String Binary
RS("b").AppendChunk (Pre)
if arg3 <> "" then 'Add the Binary File Data
RS("b").AppendChunk (Arg1)
else 'Add the Binary Field Value
RS("b").AppendChunk (arg2)
end if
'If we are on the last element, add the finishing binary data
If blnLastItem then RS("b").AppendChunk (Po)
'Return the Binary to calling function
RS.Update : FormData = RS("b") : BuildFormData = FormData
'Clear up.
RS.Close : Set RS = Nothing
End Function
Private Function StringToMB(S)
'This function converts a string, to a binary string
B = ""
For I = 1 To Len(S)
B = B & ChrB(Asc(Mid(S, I, 1)))
Next
StringToMB = B
End Function
End Class


Set frmPost = New MultiPartFormPost
'Add a file (as if you clicked the browse button on a form)
frmPost.AddFile "C:\Inetpub\wwwroot\Satya\Elroiproc.txt","proof_fi le"
'Add a Form Field
frmPost.AddField "number","54169-15577.1"
frmPost.AddField "id","451"
frmPost.AddField "SUBMIT","SUBMIT"
'you can call the above steps as many times as nessesary
'next, we send the output to the form
frmPost.Send("http://SERVER2(DESTINATION)/XXXimport/code/upload.cgi")

Response.Write strDownloadedCode1&"<br>"
Set frmPost = Nothing

%>


Mike 01-02-2006 09:08 AM

Re: Urgent Deliverable
 

kalikoi@gmail.com wrote:
> Hi All
>
> when i execute the following code i'm getting the error
>
> ************************************************** **************************
> Content-type: text/html
> Software error:
> Malformed multipart POST
> ************************************************** ***************************
>
>
> <%
> dim strDownloadedCode1
> Class MultiPartFormPost
> Public Boundary
> Private NewData
> Private PreviousData
> Private ItemString
> Private blnLastItem
> dim http
> 'The next two functions build up a string of form elements and files to
> add
> 'to the form post.
> Public Sub AddFile(LocalPath,FieldName)
> ItemString = ItemString & "FILE^^" & LocalPath & "^^" & FieldName &
> "||"
> End Sub
> Public Sub AddField(FieldName,FieldValue)
> ItemString = ItemString & "FIELD^^" & FieldName & "^^" & FieldValue &
> "||"
> End Sub
> Public Function Send(URL)
> If Boundary = "" then Boundary =
> "http://SERVER2(DESTINATION)/XXXimport/code/upload.cgi-MultipartFormPost"
> 'Default Boundary
> 'Remove the last divider element
> ItemString = left(itemstring,len(itemstring) - 2)
> 'Create an array of the various form elements to post
> Items = Split(ItemString,"||")
> For count = 0 to ubound(Items)
> 'Preserve the Current Binary Data
> PreviousData = NewData
> 'Grab the data needed to post each form element
> ItemPart = Split(Items(Count),"^^")
> 'Are we dealing with the last element?
> If count = UBound(Items) Then blnLastItem = True
> If ItemPart(0) = "FILE" Then
> AddItem 0,ItemPart(1),ItemPart(2) 'Add File
> else
> AddItem 1,ItemPart(1),ItemPart(2) 'Add Field
> end if
> Next
> 'Create HTTP object to Post the data
> Set http = CreateObject("MSXML2.ServerXMLHTTP")
> http.Open "POST", URL, False
>
> http.setRequestHeader "Content-Type", "multipart/form-data; boundary="
> + Boundary
> 'Send the Data, and grab the response.
>
> http.send NewData
> If http.readyState <> 4 then
> http.waitForResponse 10
> End If
> strDownloadedCode1 = http.responseText
> set http = Nothing
>
> End Function
> Private Sub AddItem(FType,arg1, arg2)
> If FType = 1 then 'Add field
> NewData = BuildFormData(arg1, arg2,"")
> else 'Add file
> Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
> 'Does the file exist?
> if Not objFSO.FileExists(arg1) then Exit Sub
> 'Grab the file data as binary.
> Set Stream = CreateObject("ADODB.Stream")
> Stream.Type = 1 : Stream.Open : Stream.LoadFromFile arg1
> FileContents = stream.read
> 'Build this elements RAW HTTP Data
> NewData = BuildFormData(FileContents, arg1, arg2)
> 'Clear up!
> stream.close : set stream = nothing : Set FSO = Nothing
> end if
> End Sub
> Private Function BuildFormData(arg1, arg2, arg3)
> 'Have any items been added yet?
> If lenb(PreviousData) > 0 then
> pre = vbCrLf
> else
> pre = ""
> end if
> 'Arg3 will be blank if dealing with a Field Element
> If arg3 <> "" then 'File Element
> 'Set the Element's preceding HTTP String
> Pre = Pre & Boundary & vbCrLf & "Content-Disposition: form-data; " & _
> "name=""" & arg3 & """; filename=""" & arg2 & """" & vbCrLf & _
> "Content-Type: application/upload" & vbCrLf & vbCrLf
> else 'Field Element
> 'Set the Element's preceding HTTP String
> Pre = Pre & Boundary & vbCrLf & "Content-Disposition: form-data; " & _
> "name=""" & arg1 & """" & vbcrlf & vbcrlf
> end if
> 'Are we dealing with the last element?
> If blnLastItem then
> 'Set the last element's finishing HTTP String
> Po = vbcrlf & Boundary + "--" + vbCrLf
> else
> Po = ""
> end if
> 'Create a recordset instance so we can manipulate binary data
> Set RS = CreateObject("ADODB.Recordset")
> If arg3 <> "" then 'File Element
> RS.Fields.Append "b", 205, Len(Pre) + LenB(arg1) + Len(Po)
> else 'Field Element
> RS.Fields.Append "b", 205, Len(Pre) + Len(arg2) + Len(Po)
> end if
> RS.Open : RS.AddNew 'Create a record within the recordset object
> LenData = Len(Pre)
> 'Convert the preceeding HTTP String to binary
> RS("b").AppendChunk (StringToMB(Pre) & ChrB(0))
> Pre = RS("b").GetChunk(LenData) : RS("b") = ""
> If blnLastItem then ' Last element?
> 'Convert the last element's finishing HTTP String to binary
> LenData = Len(Po) : RS("b").AppendChunk (StringToMB(Po) & ChrB(0))
> Po = RS("b").GetChunk(LenData) : RS("b") = ""
> end if
> if arg3 = "" then 'Convert Field's Value to binary.
> LenData = Len(arg2) : RS("b").AppendChunk (StringToMB(arg2) & ChrB(0))
> arg2 = RS("b").GetChunk(LenData) : RS("b") = ""
> end if
> 'If there was already Binary Data (form elements), then we add this in
> front
> 'of this element's binary data
> If LenB(PreviousData) > 0 then RS("b").AppendChunk (PreviousData)
> 'Add the preceding HTTP String Binary
> RS("b").AppendChunk (Pre)
> if arg3 <> "" then 'Add the Binary File Data
> RS("b").AppendChunk (Arg1)
> else 'Add the Binary Field Value
> RS("b").AppendChunk (arg2)
> end if
> 'If we are on the last element, add the finishing binary data
> If blnLastItem then RS("b").AppendChunk (Po)
> 'Return the Binary to calling function
> RS.Update : FormData = RS("b") : BuildFormData = FormData
> 'Clear up.
> RS.Close : Set RS = Nothing
> End Function
> Private Function StringToMB(S)
> 'This function converts a string, to a binary string
> B = ""
> For I = 1 To Len(S)
> B = B & ChrB(Asc(Mid(S, I, 1)))
> Next
> StringToMB = B
> End Function
> End Class
>
>
> Set frmPost = New MultiPartFormPost
> 'Add a file (as if you clicked the browse button on a form)
> frmPost.AddFile "C:\Inetpub\wwwroot\Satya\Elroiproc.txt","proof_fi le"
> 'Add a Form Field
> frmPost.AddField "number","54169-15577.1"
> frmPost.AddField "id","451"
> frmPost.AddField "SUBMIT","SUBMIT"
> 'you can call the above steps as many times as nessesary
> 'next, we send the output to the form
> frmPost.Send("http://SERVER2(DESTINATION)/XXXimport/code/upload.cgi")
>
> Response.Write strDownloadedCode1&"<br>"
> Set frmPost = Nothing
>
> %>


This is a classic ASP news group. Your question relates to ASP.NET.
You are much more likely to find someone to help you in one of the .NET
groups. I suggest microsoft.public.dotnet.framework.aspnet

Mike


kalikoi@gmail.com 01-02-2006 10:47 AM

Re: Urgent Deliverable
 
Hi Mike

This code is in asp only.Not dotnet.



All times are GMT. The time now is 03:29 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57