I'm sending POST request using URLLoader and URLRequest with XML data. Then API sends response with redirect page(Location header) and i want to get this URL. How do I catch this response?
UPD:
Event.COMPLETE in debugger:
event = flash.events.Event (#6e1edf9)
bubbles = false
cancelable = false
currentTarget = flash.net.URLLoader (#418e241)
[inherited] =
bytesLoaded = 1
bytesTotal = 0
data = " "
dataFormat = "text"
stream = flash.net.URLStream (#77c5fb9)
[inherited] =
bytesAvailable = 0
connected = true
endian = "bigEndian"
objectEncoding = 3
eventPhase = 2
target = flash.net.URLLoader (#418e241)
[inherited] =
bytesLoaded = 1
bytesTotal = 0
data = " "
dataFormat = "text"
stream = flash.net.URLStream (#77c5fb9)
type = "complete"
Listen on the httpResponseStatus event of the URLLoader. The event details contains a property called responseHeaders that can provide you with location header. See http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html#event:httpResponseStatus for details.
Also, to prevent redirect you can set followRedirects on URLRequest to false. See http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html#followRedirects for details.
Related
This particular question has been asked and answered, but no matter what I try I cannot get this to work. At this point I'm somewhat ready to toss my computer out the window..
No matter what combinations i try, it still fails at:
oStream.write imagebinarydata
Here is the code with comments:
sFileName = Server.MapPath("grafer/test.png")
ByteArray = Request.Form("imageData")
ByteArray = [DATA-URI String] 'This string shows the image perfectly fine, in an image tag in the top of the page so it should be perfectly ok?
response.write ("Decoded: " & Base64Decode(ByteArray)) '<- Writes 'PNG' ?
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Set oStream = Server.CreateObject("ADODB.Stream")
oStream.type = adTypeBinary
oStream.open
imagebinarydata = Base64Decode(ByteArray)
oStream.write imagebinarydata '<- FAILS
'Error:
'ADODB.Stream error '800a0bb9'
'Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
'Use this form to overwrite a file if it already exists
oStream.savetofile sFileName, adSaveCreateOverWrite
oStream.close
set oStream = nothing
response.write("success")
Function Base64Decode(ByVal vCode)
Dim oXML, oNode
Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
Set oNode = oXML.CreateElement("base64")
oNode.dataType = "bin.base64"
oNode.text = vCode
Base64Decode = Stream_BinaryToString(oNode.nodeTypedValue)
Set oNode = Nothing
Set oXML = Nothing
End Function
Function Stream_BinaryToString(Binary)
Const adTypeText = 2
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream 'As New Stream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save text/string data.
BinaryStream.Type = adTypeBinary
'Open the stream And write text/string data To the object
BinaryStream.Open
BinaryStream.Write Binary
'Change stream type To binary
BinaryStream.Position = 0
BinaryStream.Type = adTypeText
'Specify charset For the source text (unicode) data.
If Len(CharSet) > 0 Then
BinaryStream.CharSet = CharSet
Else
BinaryStream.CharSet = "us-ascii"
End If
'Open the stream And get binary data from the object
Stream_BinaryToString = BinaryStream.ReadText
End Function
If you are trying to save you can use this function
function SaveToBase64 (base64String)
ImageFileName = "test.jpg"
Set Doc = Server.CreateObject("MSXML2.DomDocument")
Set nodeB64 = Doc.CreateElement("b64")
nodeB64.DataType = "bin.base64"
nodeB64.Text = Mid(base64String, InStr(base64String, ",") + 1)
dim bStream
set bStream = server.CreateObject("ADODB.stream")
bStream.type = 1
bStream.Open()
bStream.Write( nodeB64.NodeTypedValue )
bStream.SaveToFile(Server.Mappath("Images/" & ImageFileName), 2 )
bStream.close()
set bStream = nothing
end function
I am coding an ASP application where a users data will be stored in a cookie(that expires in 24 hours) and when the program is run, it is supposed to search that cookie, and add whatever was in the cookie to the current users value, then proceed through the code.
Dim I As Integer ' iterator for cookie search
Dim foundcookie As Boolean = False ' flag if cookie found
Dim stakenow As Integer ' current stake held here
stakenow = stake.Text
Dim currentname As String
currentname = name.Text
For I = 0 To Request.Cookies.Count - 1
If Request.Cookies.Item(I).Name = currentname Then
foundcookie = True
stakenow = stakenow + Request.Cookies.Item(I).Value
currentstake.Text = currentstake.Text + stakenow.ToString
Request.Cookies.Item(I).Value = stakenow.ToString
Request.Cookies.Item(I).Expires = DateTime.Now.AddHours(24)
End If
Next
If Not foundcookie Then
Dim nameCookie As New HttpCookie(currentname)
nameCookie.Value = stakenow.ToString
nameCookie.Expires = DateTime.Now.AddHours(24)
Response.Cookies.Add(nameCookie)
currentstake.Text = currentstake.Text + stakenow.ToString
End If
This code works, the first time, it creates a cookie with a value, say 150. Then the next time the code is run and the users "stake" that they entered was 150 again, the current stake updates to 300. However the 3rd time run, if the user enters 100, we would want the users stake now to be 400, however is is only 250. I see this error is coming from the updated value not being correctly written back to the cookie, thus the addition only coming from the original value when the cookie was created, and the typed value. I have tried using request and response cookies and have had no luck. Any suggestions?
Use the HttpCookieCollection.Set Method so that the updated cookie gets back to the client:
If Request.Cookies.Item(I).Name = currentname Then
foundcookie = True
stakenow = stakenow + Request.Cookies.Item(I).Value
currentstake.Text = currentstake.Text + stakenow.ToString
Dim objCookie As HttpCookie = Request.Cookies.Item(I)
objCookie.Value = stakenow.ToString()
objCookie.Expires = DateTime.Now.AddHours(24)
HttpContext.Current.Response.Cookies.Set(objCookie)
End If
I get following error occasionally while running my flex application. I dont know what is wrong as it works intermittently.
Error occured (mx.messaging.messages::ErrorMessage)#0
body = ""
clientId = "DirectHTTPChannel0"
correlationId = "ACB1E8D4-51AF-21B9-E440-8ADBA0D4301E"
destination = ""
extendedData = (null)
faultCode = "Server.Error.Request"
faultDetail = "Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://localhost/api/wireless/lookupNumber/6501234567/"]. URL: http://localhost/api/wireless/lookupNumber/6501234567/"
faultString = "HTTP request error"
headers = (Object)#1
DSStatusCode = 0
messageId = "21CFD7A0-209E-81E2-8416-8ADBAC4F6B69"
rootCause = (flash.events::IOErrorEvent)#2
bubbles = false
cancelable = false
currentTarget = (flash.net::URLLoader)#3
bytesLoaded = 0
bytesTotal = 0
data = ""
dataFormat = "text"
errorID = 0
eventPhase = 2
target = (flash.net::URLLoader)#3
text = "Error #2032: Stream Error. URL: http://localhost/api/wireless/lookupNumber/6501234567/"
type = "ioError"
timestamp = 0
timeToLive = 0
Can you please guide me ?
Thanks
The code below tries to clear the cookies for all domains once a user logs out of the system. For some reason, only the last domain in the array is cleared. Why does this happen? Am I doing something wrong?
For example, if I change the size of the array to 4 and then change the for loop to only go to 3, then it only logs me out of y.xcv.com.
As a sidenote, I have this loop working on a different server that uses a slightly different function to clear the cookies.
Edit: Code updated per suggestions below. Now it fails on the "as HttpCookie" line. Do I need to include some library?
Dim aDomain(12)
Dim ESidCookie, WIdCookie, EBidCookie, TSidAccessCookie, PSidAccessCookie, SSidCookie As HttpCookie
aDomain(0) = ".x.com"
aDomain(1) = "y.x.com"
aDomain(2) = "y.x.com"
aDomain(3) = "y.xcv.com"
aDomain(4) = "x.com"
aDomain(5) = "y.z.a.com"
aDomain(6) = "y.z.a.com"
aDomain(7) = "z.a.com"
aDomain(8) = ""
aDomain(9) = "y.x.com"
aDomain(10) = "y.x.com"
aDomain(11) = "y.x.com"
for count = 0 to 11
strDomain = aDomain(count)
response.Write count & "/" & strDomain
ESidCookie = New HttpCookie("oneCookie")
ESidCookie.Domain = strDomain
ESidCookie.Path = "/"
ESidCookie = ""
ESidCookie.Expires = now() - 100
Response.Cookies.Add(ESidCookie)
WIdCookie = New HttpCookie("twoCookie")
WIdCookie.Domain = strDomain
WIdCookie.Path = "/"
WIdCookie = ""
WIdCookie.Expires = now() - 100
Response.Cookies.Add(WIdCookie)
EBidCookie = New HttpCookie("threeCookie")
EBidCookie.Domain = strDomain
EBidCookie.Path = "/"
EBidCookie = ""
EBidCookie.Expires = now() - 100
Response.Cookies.Add(EBidCookie)
TSidAccessCookie = New HttpCookie("fourCookie")
TSidAccessCookie.Path = "/"
TSidAccessCookie = "LoggedOut"
Response.Cookies.Add(TSidAccessCookie)
PSidAccessCookie = New HttpCookie("fiveCookie")
PSidAccessCookie.Domain = strDomain
PSidAccessCookie.Path = "/"
PSidAccessCookie = ""
PSidAccessCookie.Expires = now() - 100
Response.Cookies.Add(PSidAccessCookie)
SSidCookie = New HttpCookie("sixCookie")
SSidCookie.Domain = strDomain
SSidCookie.Path = "/"
SSidCookie = ""
SSidCookie.Expires = now() - 100
Response.Cookies.Add(SSidCookie)
next
Any help is appreciated. Thanks!
The Response.Cookies collection is keyed off of the cookie name so you are just changing the domain of the same cookie each time you go through your loop. That's why the last one wins.
You could try creating a new cookie object and adding that to the Response.Cookies collection in your loop instead.
If you want to clear all cookies you will should create all new ones with the same name. Here is a basic example that should get you going:
Dim newCookie As HttpCookie
For i As Integer = 0 To 10
' creating a new cookie each time
newCookie = New HttpCookie(cookieNames(i))
' expire the cookie
newCookie.Expires = DateTime.Now.AddDays(-1)
' storing the new cookie each time
Response.Cookies.Add(newCookie)
Next
It doesn't look like your creating all new cookies and adding them to the response properly.
I have code that accepts binary data via POST and reads in an array of bytes. For files larger than 200 Kb, the operation fails. I've checked with my sysadmin (we're running IIS 7) to see if there was a limit in our configuration and he says there is none, and suspects it is a problem with the code. Does anybody here see any potential problems? Here is my code:
Public Sub Initialize
If Request.TotalBytes > 0 Then
Dim binData
binData = Request.BinaryRead(Request.TotalBytes) ' This line fails'
getData binData
End If
End Sub
Private Sub getData(rawData)
Dim separator
separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1)
Dim lenSeparator
lenSeparator = LenB(separator)
Dim currentPos
currentPos = 1
Dim inStrByte
inStrByte = 1
Dim value, mValue
Dim tempValue
tempValue = ""
While inStrByte > 0
inStrByte = InStrB(currentPos, rawData, separator)
mValue = inStrByte - currentPos
If mValue > 1 Then
value = MidB(rawData, currentPos, mValue)
Dim begPos, endPos, midValue, nValue
Dim intDict
Set intDict = Server.CreateObject("Scripting.Dictionary")
begPos = 1 + InStrB(1, value, ChrB(34))
endPos = InStrB(begPos + 1, value, ChrB(34))
nValue = endPos
Dim nameN
nameN = MidB(value, begPos, endPos - begPos)
Dim nameValue, isValid
isValid = True
If InStrB(1, value, stringToByte("Content-Type")) > 1 Then
begPos = 1 + InStrB(endPos + 1, value, ChrB(34))
endPos = InStrB(begPos + 1, value, ChrB(34))
If endPos = 0 Then
endPos = begPos + 1
isValid = False
End If
midValue = MidB(value, begPos, endPos - begPos)
intDict.Add "FileName", trim(byteToString(midValue))
begPos = 14 + InStrB(endPos + 1, value, stringToByte("Content-Type:"))
endPos = InStrB(begPos, value, ChrB(13))
midValue = MidB(value, begPos, endPos - begPos)
intDict.Add "ContentType", trim(byteToString(midValue))
begPos = endPos + 4
endPos = LenB(value)
nameValue = MidB(value, begPos, ((endPos - begPos) - 1))
Else
nameValue = trim(byteToString(MidB(value, nValue + 5)))
End If
If isValid = True Then
intDict.Add "Value", nameValue
intDict.Add "Name", nameN
dict.Add byteToString(nameN), intDict
End If
End If
currentPos = lenSeparator + inStrByte
Wend
End Sub
Here is the error that appears in the logs:
Log Name: Application
Source: Active Server Pages
Date: 11/11/2010 2:15:35 PM
Event ID: 5
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Computer: xxxxx.xxxxx.xxx
Description:
Error: File /path-to-file/loader.asp Line 36 Operation not Allowed. .
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Active Server Pages" />
<EventID Qualifiers="49152">5</EventID>
<Level>2</Level>
<Task>0</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2010-11-11T19:15:35.000Z" />
<EventRecordID>19323</EventRecordID>
<Channel>Application</Channel>
<Computer>PHSWEB524.partners.org</Computer>
<Security />
</System>
<EventData>
<Data>File /mghdev/loader.asp Line 36 Operation not Allowed. </Data>
</EventData>
</Event>
By default the limit for the entity size in a POST request is 200K, hence your error.
You can increase that limit open IIS Manager and navigate the tree to your application. Double click the "ASP" icon in the main panel. Expand the "Limits" category. Modify the "Maximum Requesting Entity Body Limit" to a larger value.
If this is for a public web-site be careful as to the limit you set, the purpose of the limit is to prevent malicious POSTs overwhelming the site.
If you read the specifications of the BinaryRead method, you will see that the parameter is actually an out parameter as well. The BinaryRead method is trying to change the value of Request.TotalBytes which it can't do. TotalBytes is read-only.
You can easily fix this by assigning TotalBytes to a variable and passing that in instead. This is what the example code shows in the MSDN documentation.
If the BinaryRead read a different amount of data, the variable will reflect the size of the read.
Two Settings are required in IIS under the "Limit Properties" section
1- Maximum Requesting Entity Body Limit (please not that it is in bytes). You have to set the value according to your maximum file size e-g- 40MB(40000000 bytes).
2)- Script Time-out . Its default value is "00:01:30: which is 90 seconds. Increase it according to the time required by your code to run. I set it to 5 minutes and it solved the problem.