Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Empty return from http page

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-13-2009, 07:19 PM
Knows the basics
 
Join Date: Jan 2009
Location: Germany and Canarias
Posts: 58
Default Empty return from http page

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 by junglejet : 02-13-2009 at 07:23 PM.
Reply With Quote
  #2 (permalink)  
Old 02-14-2009, 11:04 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,726
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

What error do you get (after commenting ErrorLabel)?
Reply With Quote
  #3 (permalink)  
Old 02-14-2009, 02:17 PM
Basic4ppc Veteran
 
Join Date: Jan 2008
Posts: 215
Default

Quote:
Originally Posted by junglejet View Post
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
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.
Reply With Quote
  #4 (permalink)  
Old 02-14-2009, 04:00 PM
Knows the basics
 
Join Date: Jan 2009
Location: Germany and Canarias
Posts: 58
Default

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.
Reply With Quote
  #5 (permalink)  
Old 02-14-2009, 04:57 PM
Basic4ppc Veteran
 
Join Date: Jan 2008
Posts: 215
Default

Quote:
Originally Posted by junglejet View Post
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:
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.
Reply With Quote
  #6 (permalink)  
Old 02-14-2009, 06:46 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by junglejet View Post
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.
Perhaps you could use my http://www.basic4ppc.com/forum/addit...html#post12486 in your Errorlabel code block to see what the error actually is and decide what to do.

Quote:
- because your code exits with "return" instead of "return string" then it seems to throw an error on main.
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 by agraham : 02-15-2009 at 09:14 AM.
Reply With Quote
  #7 (permalink)  
Old 02-14-2009, 09:52 PM
Knows the basics
 
Join Date: Jan 2009
Location: Germany and Canarias
Posts: 58
Default

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?
Reply With Quote
  #8 (permalink)  
Old 02-15-2009, 12:02 AM
Basic4ppc Veteran
 
Join Date: Jan 2008
Posts: 215
Default

Quote:
Originally Posted by junglejet View Post
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?
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.
Reply With Quote
  #9 (permalink)  
Old 02-15-2009, 08:39 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by junglejet View Post
I believe the exceptions.dll cannot be merged?
What makes you believe that? From the post http://www.basic4ppc.com/forum/addit...html#post12486
Quote:
Source code for dll merging posted. Put it in your Basic4ppc Deskop\Libraries folder
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read a wap page ? thestronger Questions (Windows Mobile) 2 11-02-2008 09:05 PM
Can a sub return more than 1 value ? TWELVE Questions (Windows Mobile) 13 05-28-2008 09:58 AM
How to make Loading page superbabicka Questions (Windows Mobile) 3 03-31-2008 02:41 PM
interacting with a web page..... Cableguy Questions (Windows Mobile) 0 03-17-2008 08:00 PM
Error loading empty csf file Scubaticus Bug Reports 4 07-07-2007 11:41 AM


All times are GMT. The time now is 03:55 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0