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
  #21 (permalink)  
Old 02-10-2010, 11:09 PM
konisek's Avatar
Knows the basics
 
Join Date: Jan 2009
Posts: 52
Default

Sorry, I still don't understand it how to read data into array asynchronously. I looked at the help file but still am not sure. Is this the correct way?
Code:
Sub Button1_Click
....
stream.WriteBytes(stream.StringToBytes(name))
response.Value = request.AsyncResponse
....
"buffer operation"
....
End Sub

Sub request_Response
Dim buffer(1024As byte
count = bin.ReadBytes(buffer(),
1024)
End Sub
Reply With Quote
  #22 (permalink)  
Old 02-12-2010, 07:18 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

The stream is first saved to a file. Then you can open it with BinaryFile and read it to an array:
Code:
Sub Globals
    
Dim buffer(0As byte
End Sub

Sub App_Start
    Form1.Show
    request.New1(
"http://www.basic4ppc.com")
    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.GetAsyncStream(AppPath & 
"\tempfile"'Stream is saved to this file
      Else
            
Msgbox("Error getting response: " & request.ErrorMessage & CRLF _
            & 
"Response code: " & request.ResponseCode)
      
End If
End Sub

Sub response_Stream
    
'file is ready
    FileOpen(c, AppPath & "\tempfile", cRandom)
    binaryFile.New1(c, 
False)
    
Dim buffer(FileSize(AppPath & "\tempfile")) As byte
    
Msgbox(binaryFile.ReadBytes(buffer(), ArrayLen(buffer())))
    FileClose(c)
    
End Sub
Attached Files
File Type: sbp 1.sbp (310 Bytes, 12 views)
__________________
Basic4android documentation
Reply With Quote
  #23 (permalink)  
Old 02-21-2010, 10:21 PM
konisek's Avatar
Knows the basics
 
Join Date: Jan 2009
Posts: 52
Default

Thank you for the help.

Additionally, I tested your example HTTP-POST.sbp from the first page and discovered this:

1) When I run it on PC, I get the response immediately.
2) When I run it on PPC connected via wifi, I get the response in 39 seconds.
3) When I run it on PPC connected via gprs, I get the response also in 39 seconds.

I expected that the case (2) via wifi would have been much faster than case (3) but it is not. Is it just my case? Therefore I also tested how quickly the internet browser starts to show pages when I use wifi and then gprs. In both cases there is the same unappropriate delay from starting the internet icon upto actual show of the internet page on PDA screen. Maybe its only my case and my PDA needs a hard reset. Can anyone test and post the reply?

Last edited by konisek : 02-21-2010 at 10:36 PM.
Reply With Quote
  #24 (permalink)  
Old 03-03-2010, 09:15 PM
konisek's Avatar
Knows the basics
 
Join Date: Jan 2009
Posts: 52
Cool

I upgraded from WM6.1 to WM6.5 and the times shortened:
ad 2)...response in 6 seconds.
ad 3)...response in 6 seconds
Reply With Quote
  #25 (permalink)  
Old 08-05-2010, 09:14 PM
Senior Member
 
Join Date: Apr 2008
Location: Duesseldorf, Germany
Posts: 154
Default

Hi Erel,

for certain reasons, i changed all my http stuff to UTF-8, which works fine on desktop, but returns error from server on device.

After some testing and sniffing with wireshark i believe there's a bug in the http.dll on the device.Earlier, i calculated the ContentLenght by myself because this was required.With newer version of http.dll ( not sure where it was introduced), i saw that it is not needed anymore to calculate the ContentLength, this was done by http.dll.This works fine, but it looks like, that the device http.dll does not calculate correctly as soon as UTF-8 comes into the play.This is even true if no UTF-8 char is sent.

The only difference between desktop(working) and device(not working) was the Content-Length header, there is a difference of 6 bytes in length ( device 6 bytes less than on desktop).


Can you have a look into that matter..?


regards,

TWELVE
Reply With Quote
  #26 (permalink)  
Old 08-06-2010, 05:24 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Can you post a small program that demonstrates this problem?
__________________
Basic4android documentation
Reply With Quote
  #27 (permalink)  
Old 08-06-2010, 02:48 PM
Senior Member
 
Join Date: Apr 2008
Location: Duesseldorf, Germany
Posts: 154
Default

Hi Erel,

thanks for the reply.After some more debugging it turned out that i hit rare bug in our server scripts, for some reasons i can explain now it only occured on the device then.

So no further action required from your side...;-)

regards,

TWELVE
Reply With Quote
  #28 (permalink)  
Old 09-03-2010, 04:51 PM
Junior Member
 
Join Date: Sep 2008
Posts: 16
Default Erel!

Quote:
Originally Posted by Erel View Post
I'm using a simple php file that prints the POST variables.
Code:
Sub Globals

End Sub

Sub App_Start
    Form1.Show
End Sub

Sub Button1_Click
    request.New1(
"http://www.basic4ppc.com/print.php")
    request.Method = 
"POST"
    Request.ContentType = 
"application/x-www-form-urlencoded"
    stream.New1(Request.GetStream,
True
    name = 
"First=Erel&Last=Uziel"
    stream.WriteBytes(stream.StringToBytes(name))
    response.New1
    request.GetAsyncResponse
End Sub

Sub request_Response
    
If request.ResponseCode = 200 Then
        response.Value = request.AsyncResponse
        response.GetAsyncString
    
Else
        
Msgbox(request.ErrorMessage)
    
End If
End Sub

Sub response_Stream
    TextBox1.Text = response.AsyncString
End Sub

could you show your php code? please?
Reply With Quote
  #29 (permalink)  
Old 09-03-2010, 06:02 PM
sitajony's Avatar
Basic4ppc Veteran
 
Join Date: Mar 2010
Location: France
Posts: 416
Awards Showcase
Beta Tester 
Total Awards: 1
Default

I think that it's:
Code:
<?
$first=$_POST[
"First"];
$last=$_POST[
"Last"];
echo $first. 
" " .$last;
?>
Reply With Quote
  #30 (permalink)  
Old 09-03-2010, 08:39 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Here:
Code:
<?php
print 
"POST variables:\r\n";
var_dump($_POST);
print 
"\r\nGET variables:\r\n";
var_dump($_GET);
?>
__________________
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