Link to home
Start Free TrialLog in
Avatar of pwerstreak
pwerstreak

asked on

BinaryRead and inserting into SafeArray

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
Avatar of sybe
sybe

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)
Avatar of pwerstreak

ASKER

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
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
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
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.

'----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
ASKER CERTIFIED SOLUTION
Avatar of sybe
sybe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.
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