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

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips > Official Updates
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Official Updates Updates to official libraries could be found here.
This forum is only available to licensed users.

HTTP library v1.5 - Asynchronous calls

Reply
 
LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old 01-05-2010, 07:23 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

V1.61 is attached with the new method.
Please tell me if it works as required.
Attached Files
File Type: zip HTTP.zip (6.1 KB, 40 views)
__________________
Basic4android documentation
Reply With Quote
  #12 (permalink)  
Old 01-06-2010, 01:52 AM
Junior Member
 
Join Date: Sep 2009
Posts: 47
Default

Tested, it work perfectly. Thanks Erel!
Reply With Quote
  #13 (permalink)  
Old 01-11-2010, 02:00 AM
Junior Member
 
Join Date: Sep 2009
Posts: 47
Default

My apps require trigger multiple http download & I'm hit with occassionaly "timeout -1" problems on device, strange that it doesn't happen on desktop.

Upon a search on forum, I noted quite a numbers of forumer reported such issue & some solution is to extend the timeout.

But now I realized the actual problem, I was following the sample in the help file for both GetAsyncString & GetAsyncStream, & it does not include response.close, which may cause problem when initiate the 2nd download, which causes timeout, but most likely will success again when try for the 3rd time.

You may want to include it in the sample in yr next release

---------------

//GetAsyncString

Sub Globals
URL = "http://www.basic4ppc.com"
End Sub


Sub App_Start
Form1.Show
request.New1(URL)
response.New1
request.GetAsyncResponse
End Sub


Sub request_Response
If request.ResponseCode = 200 Then '200 is the code of successful connections.
response.Value = request.AsyncResponse
response.GetAsyncString
Else
Msgbox("Error getting response: " & request.ErrorMessage & CRLF _
& "Response code: " & request.ResponseCode)
End If
End Sub


Sub response_Stream
response.close
TextBox1.Text = response.AsyncString
End Sub
Reply With Quote
  #14 (permalink)  
Old 01-11-2010, 07:49 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Thanks.
__________________
Basic4android documentation
Reply With Quote
  #15 (permalink)  
Old 02-05-2010, 12:48 AM
konisek's Avatar
Knows the basics
 
Join Date: Jan 2009
Posts: 52
Default syncrhonous -> asynchronous call

I use the foolowing code:
Code:
Sub Button1_Click
....
response.New1
request.New1 (URL)
request.Method = 
"POST"
request.TimeOut = 
60000
request.ContentType = 
"application/x-www-form-urlencoded"

stream.New1(Request.GetStream,
True)
stream.WriteBytes(stream.StringToBytes(name))
response.Value = request.GetResponse

'reading cookie
regex.New1("PHPSESSID=.[a-zA-Z0-9]+")
match.New1
match.Value = 
regex.Match(response.Headers)
Session_ID = match.String

'Get the response into array
bin.New1(response.GetStream, True)
bit.New1
Dim buffer(1024As byte
count = bin.ReadBytes(buffer(),
1024)
For i = 0 To ArrayLen(buffer())-1
retezec = retezec & 
" " & buffer(i)
Next 
Msgbox(retezec)

'operations with buffer()
....
TextBox4.Text = 
bit.BytesToString(buffer(), 4, count)
response.Close
End Sub
Can you, please, advise how to use the asynchronous calls, esp. with respect to cookie? I read the response into array rather than
Code:
TextBox4.Text = Response.GetString
Reply With Quote
  #16 (permalink)  
Old 02-05-2010, 10:12 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

You should use request.GetAsyncResponse instead of GetResponse. Then in the Response event you should call response.GetAsyncStream.

See the example in the manual: HTTP
__________________
Basic4android documentation
Reply With Quote
  #17 (permalink)  
Old 02-05-2010, 03:50 PM
konisek's Avatar
Knows the basics
 
Join Date: Jan 2009
Posts: 52
Default

Yes, I have tried it. It gives me a NullReferenceException Error in match.Value = regex.Match(response.Headers)
But I suppose that my structure is not correct:
Code:
Sub Button1_Click
....
response.New1
request.New1 (URL)
request.Method = 
"POST"
request.TimeOut = 
60000
request.ContentType = 
"application/x-www-form-urlencoded"

stream.New1(Request.GetStream,
True)
stream.WriteBytes(stream.StringToBytes(name))
<font color=
"Red">request.GetAsyncResponse</font>

'reading cookie
regex.New1("PHPSESSID=.[a-zA-Z0-9]+")
match.New1
match.Value = 
regex.Match(response.Headers)
Session_ID = match.String

'operations with buffer() <font color="Blue">'Here I want to use the buffer from response_Stream</font>
....
TextBox4.Text = 
bit.BytesToString(buffer(), 4, count)
response.Close
End Sub

Sub request_Response
response.Value = <font color=
"Red">request.GetAsyncResponse</font>
<font color=
"Red">response.GetAsyncStream</font>
End Sub

Sub response_Stream  <font color="Blue">'Here I want to read the response and put it to array. And then I want to use it in  Sub Button1_click</font>
'
Get the response into array
bin.New1(response.GetStream, True)
bit.New1
Dim buffer(1024As byte
count = bin.ReadBytes(buffer(),
1024)
For i = 0 To ArrayLen(buffer())-1
retezec = retezec & 
" " & buffer(i)
Next 
Msgbox(retezec)
End Sub

Last edited by konisek : 02-05-2010 at 03:54 PM.
Reply With Quote
  #18 (permalink)  
Old 02-06-2010, 11:12 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

The response object is only available after this line:
Code:
response.Value = request.GetAsyncResponse
So your code should look something like:
Code:
...
request.GetAsyncResponse
End Sub

Sub request_Response

response.Value = request.GetAsyncResponse
regex.New1("PHPSESSID=.[a-zA-Z0-9]+")
match.New1
match.Value = 
regex.Match(response.Headers)
Session_ID = match.String
...
About the stream, see the manual for an example of using Response.GetAsyncStream: HTTP
__________________
Basic4android documentation
Reply With Quote
  #19 (permalink)  
Old 02-06-2010, 11:27 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Sorry to jump in but shouldn't

response.Value = request.GetAsyncResponse

actually be

response.Value = request.AsyncResponse
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #20 (permalink)  
Old 02-06-2010, 11:47 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Yes. You are of course correct.
__________________
Basic4android documentation
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
HTTP library v1.4 Erel Official Updates 2 10-29-2008 10:11 PM
HTTP Library bish0p Questions (Windows Mobile) 4 09-12-2008 02:24 PM
Using Asynchronous GetXmlHttpObject() vs threads aerohost Questions (Windows Mobile) 21 08-22-2008 09:12 AM
HTTP library v1.3 Erel Official Updates 1 03-15-2008 11:57 AM
HTTP library help agraham Bug Reports 1 01-07-2008 11:15 AM


All times are GMT. The time now is 04:39 AM.


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