I use the "standard" http download routine to upload parameters in the url string. The server may return an empty string which is ok. However the routine throws an exception and ends behind the errorlabel. Can that be avoided and empty strings handled as such? (Device only)
B4X:
Sub GetText (URL)
ErrorLabel(eURL)
Response.New1
Request.New1(URL)
Response.Value = Request.GetResponse 'This line calls the server and gets the response.
string = Response.GetString 'Get the Response string.
Response.Close
Return string
eUrl:
If buStatus.Color=cGreen Then buStatus_Click 'Stops Auto mode
Msgbox("Connection error","")
Return
End Sub
I use the "standard" http download routine to upload parameters in the url string. The server may return an empty string which is ok. However the routine throws an exception and ends behind the errorlabel. Can that be avoided and empty strings handled as such? (Device only)
B4X:
Sub GetText (URL)
ErrorLabel(eURL)
Response.New1
Request.New1(URL)
Response.Value = Request.GetResponse 'This line calls the server and gets the response.
string = Response.GetString 'Get the Response string.
Response.Close
Return string
eUrl:
If buStatus.Color=cGreen Then buStatus_Click 'Stops Auto mode
Msgbox("Connection error","")
Return
End Sub
Yes, I could ignore the exception, but there are also valid exceptions when thre is a 404 or so. That's why I prefer to correctly have the empty string processed.
Yes, I could ignore the exception, but there are also valid exceptions when thre is a 404 or so. That's why I prefer to correctly have the empty string processed.
To me that looks like you are getting the error thrown in main when you call GetText and do not get a return string. If your code is this:
B4X:
html=getText(url)
and if GetText doesn't return anything (which I believe is what is happening - others can jump in and correct me - because your code exits with "return" instead of "return string") then it seems to throw an error on main.
I think a 404 error would still return a string and not hit your error code. I think the error code is only triggered if the http call gets nothing (like on a time-out)
I've had good luck always returning the variable string in GetText and then passing the return value to another sub for evaluation.
Yes, I could ignore the exception, but there are also valid exceptions when thre is a 404 or so. That's why I prefer to correctly have the empty string processed.
The exception is definitely thrown in GetText, not the caller. An empty string reply is allowed in http protocol together with reply code 200. Every browser and the B4PPC IDE do recognize this as valid. The device (optimized) does not. I believe Andrew's proposal is best, though I believe the exceptions.dll cannot be merged?
The exception is definitely thrown in GetText, not the caller. An empty string reply is allowed in http protocol together with reply code 200. Every browser and the B4PPC IDE do recognize this as valid. The device (optimized) does not. I believe Andrew's proposal is best, though I believe the exceptions.dll cannot be merged?