Empty return from http page

Discussion in 'Questions (Windows Mobile)' started by junglejet, Feb 13, 2009.

  1. junglejet

    junglejet Active Member Licensed User

    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)

    Code:
    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
     
    Last edited: Feb 13, 2009
  2. Erel

    Erel Administrator Staff Member Licensed User

    What error do you get (after commenting ErrorLabel)?
     
  3. digitaldon37

    digitaldon37 Active Member Licensed User

    Have you tried returning the variable string on an error?
    Code:
    eUrl:
         
    If buStatus.Color=cGreen Then buStatus_Click 'Stops Auto mode
         Msgbox("Connection error","")
         
    Return string
    String will be empty, but the variable that you are setting with the GetText call will have a value set.
     
  4. junglejet

    junglejet Active Member Licensed User

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

    digitaldon37 Active Member Licensed User

    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:
    Code:
    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.
     
  6. agraham

    agraham Expert Licensed User

    Perhaps you could use my http://www.basic4ppc.com/forum/additional-libraries/2305-exceptions-handling-library.html#post12486 in your Errorlabel code block to see what the error actually is and decide what to do.

    As a technical detail just "return" by itself, and also running off the end of a Sub both return an empty string as in - return ""
     
    Last edited: Feb 15, 2009
  7. junglejet

    junglejet Active Member Licensed User

    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?
     
  8. digitaldon37

    digitaldon37 Active Member Licensed User

    I wasn't suggesting that the http was throwing an exception, I was wondering if not setting a return string was causing it.

    You are right, if it works in a browser then it should work in the B4PPC http library as well.
     
  9. agraham

    agraham Expert Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice