?
Solved

BinaryRead and inserting into SafeArray

Posted on 2003-02-20
11
Medium Priority
?
723 Views
Last Modified: 2012-08-13
Hi,
Here's my code:

     Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
     oXMLHTTP.Open "POST", "http://mysite.com/mypage.asp", False

     vntPostedData = Request.BinaryRead (Request.TotalBytes)
     oXMLHTTP.Send vntPostedData

I want to add an extra variable "Total" = "$100" to vntPostedData SafeArray before it gets posted to mypage.asp so that "Total" looks like any other Form variable.
Is this possible? Any ideas as to how I could late-add a Form post variable?
Thanks
manny
0
Comment
Question by:pwerstreak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 7987221
Why do you use Request.BinaryRead ?? The only reason would be that it contains binary code (from fileupload).

If not, then just use
Request.Form & "&Total=" & Server.URLEncode($100)

Else you have to do something like:

Request.BinaryRead & StringToByte("&Total=" & Server.URLEncode($100))

Where StringToByte is a userdefined function to convert a string to a byte.

Simplest Function for that is:

Function String2Byte(s)
    Dim sChar, i
    For i = 1 to Len(s)
        sChar = Mid(s, i, 1)
        String2Byte = String2Byte & ChrB(Asc(sChar))
    Next
End Function

(But use it only for small strings, for large strings it is very slow, and there are faster functions then)
0
 

Author Comment

by:pwerstreak
ID: 7987511
xmlhttp was used so to post to asp pages in different servers and for later expansion, and for load balancing etc... I'm not at a liberty to change it.

oXMLHTTP.Send Request.BinaryRead & StringToByte("&Total=" & Server.URLEncode($100)) results in an error "type mismatch" as Send() expects an HTTPRequest (in the form of a safearray??)

manny
0
 

Author Comment

by:pwerstreak
ID: 7987548
xmlhttp was used so to post to asp pages in different servers and for later expansion, and for load balancing etc... I'm not at a liberty to change it.

oXMLHTTP.Send Request.BinaryRead & StringToByte("&Total=" & Server.URLEncode($100)) results in an error "type mismatch" as Send() expects an HTTPRequest (in the form of a safearray??)

manny
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pwerstreak
ID: 7987611
xmlhttp was used so to post to asp pages in different servers and for later expansion, and for load balancing etc... I'm not at a liberty to change it.

oXMLHTTP.Send Request.BinaryRead & StringToByte("&Total=" & Server.URLEncode($100)) results in an error "type mismatch" as Send() expects an HTTPRequest (in the form of a safearray??)

manny
0
 
LVL 28

Expert Comment

by:sybe
ID: 7987662
don't refresh this page: your comments get repeated !!

Now I remember a bit more:
If forms are posted with multipart/form-data, then you also need a seperator. The seperator is different everytime. You'll have to understand the mechanism quite well to add something to it.

0
 

Author Comment

by:pwerstreak
ID: 8120155
'----mypage1.asp---------

    Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
    oXMLHTTP.Open "POST", "http://mysite.com/mypage2.asp", False
    vntPostedData = Request.BinaryRead (Request.TotalBytes)
    oXMLHTTP.Send vntPostedData
'-------------------------
here again, I need to add one more variable to the Request in "mypage1" before I post to "mypage2" via xmlhttp... any way I could do this?

thanks
manjil
0
 
LVL 28

Accepted Solution

by:
sybe earned 400 total points
ID: 8121282
It would be something like this, i have not tested it, but basically this is how it works.


Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
oXMLHTTP.Open "POST", "http://mysite.com/mypage2.asp", False
vntPostedData = Request.BinaryRead (Request.TotalBytes)

iEndPos = InstrB(1,vntPostedData,String2Byte(CHR(13)))
sBoundary = Byte2String(MidB(vntPostedData,1,iEndPos-1))
sFieldname = "Total"
sValue = "$100"

btOldValues = LeftB(vntPostedData,LenB(vntPostedData)-4)
btNewValues = btOldValues & String2Byte(CHR(13) & CHR(10) & "Content-Disposition: form-data; name=""" &_
    sFieldname & """" & CHR(13) & CHR(10) & CHR(13) & CHR(10) & sValue & CHR(13) & CHR(10) &_
    sBoundary & "--" & CHR(13) & CHR(10))


oXMLHTTP.Send RSString2Byte(btNewValues)


Function RSString2Byte(ByVal s)
    Dim iLenString, oRS
    Set oRS = CreateObject("ADODB.Recordset")
    iLenString = LenB(s)
    If iLenString > 0 Then
        oRS.Fields.Append "mBinary", 205, iLenString
        oRS.Open
        oRS.AddNew
        oRS("mBinary").AppendChunk s & ChrB(0)
        oRS.Update
        RSString2Byte = oRS("mBinary").GetChunk(iLenString)
        oRS.Close
    End If
    Set oRS = Nothing
End Function

Function Byte2String(s)
    Dim i
    For i = 1 to LenB(s)
        Byte2String = Byte2String & CHR(AscB(MidB(s,i,1)))
    Next
End Function

Function String2Byte(s)
    Dim sChar, i
    For i = 1 to Len(s)
        sChar = Mid(s, i, 1)
        String2Byte = String2Byte & ChrB(AscB(sChar))
    Next
End Function


0
 
LVL 28

Expert Comment

by:sybe
ID: 8121321
but now that I think of it. It would be a lot easier to add your extra values to the querystring:


sUrlToPostTo = "http://mysite.com/mypage2.asp?Total=" & Server.URLEncode("$100")

Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
oXMLHTTP.Open "POST", sUrlToPostTo, False
vntPostedData = Request.BinaryRead (Request.TotalBytes)
oXMLHTTP.Send vntPostedData

and then read the request.querystring on the receiving site
0
 

Expert Comment

by:CleanupPing
ID: 9577003
pwerstreak:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 58

Expert Comment

by:Gary
ID: 9754523
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer by sybe

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question