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
  #1 (permalink)  
Old 12-07-2008, 08:12 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default HTTP library v1.5 - Asynchronous calls

HTTP library v1.5 is attached.
The new version adds support for asynchronous calls.
You can now use Request.GetAsyncResponse to send a request to a server and get the response without blocking the main program.
When the response is available the Response event will be fired.

The response stream could also be asynchronously downloaded with Request.GetAsyncStream which downloads the stream to a temporary (or not temporary) file, or Request.GetAsyncString which builds a string out of the response. In both cases the Stream event will be fired when the process finishes retrieving the stream.
It is also possible to cancel the process and get the number of bytes downloaded (to show the progress).
The manual is available online: HTTP

Setup instructions:
- Download the zip file.
- Extract and copy HTTP.dll (library), HTTP.cs (code for merging) and HTTP.CHM (help file) to Basic4ppc folders library:
C:\Program Files\Anywhere Software\Basic4ppc Desktop\Libraries

Also replace existing copies of http.dll in the source code folder.
Attached Files
File Type: zip HTTP.zip (30.7 KB, 413 views)
__________________
Basic4android documentation
Reply With Quote
  #2 (permalink)  
Old 12-12-2008, 05:14 PM
Knows the basics
 
Join Date: Jan 2008
Posts: 64
Default

Erel, can you show a simple example how can i POST data and get the response using asynchronous calls? I'm a bit stuck... Thanks
Reply With Quote
  #3 (permalink)  
Old 12-12-2008, 05:47 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

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
Attached Files
File Type: sbp HTTP-POST.sbp (1.0 KB, 82 views)
__________________
Basic4android documentation
Reply With Quote
  #4 (permalink)  
Old 12-12-2008, 06:33 PM
Knows the basics
 
Join Date: Jan 2008
Posts: 64
Default

Thanks Erel, i've found where i made a mistake. There are many new methods in this lib, i've became puzzled a bit
Reply With Quote
  #5 (permalink)  
Old 06-11-2009, 08:50 PM
Knows the basics
 
Join Date: Aug 2008
Location: Russia, Perm
Posts: 70
Send a message via ICQ to Aspire89
Default

Hello all. The task of the next.
We need to send to the server request to view: http://site.com/page.php?lat=56.565&lng=58.424
use the following code:
Code:
request.New1("<a href="http://www.basic4ppc.com/forum/print.php" target="_blank">http://site.com/page.php</a>")
request.Method = 
"POST"
Request.ContentType = 
"application/x-www-form-urlencoded"
stream.New1(Request.GetStream,
True
name = 
"<a href="http://site.com/page.php?lat=56.565&lng=58.424" target="_blank">lat=56.565&lng=58.424</a> "
stream.WriteBytes(stream.StringToBytes(name))
response.New1
request.GetAsyncResponse
but the server does not receive the data lat=56.565&lng=58.424
script which is on the server:
PHP Code:
$data=file_get_contents('data.xml');
$data=str_replace("</markers>"""$data);
$fd=fopen('data.xml'"w+");
fwrite($fd$data);
fwrite($fd'<marker lat="' $_GET['lat'] . '" lng="' $_GET['lng'] . '"/>');
fwrite($fd"\n");
fwrite($fd'</markers>');
fclose($fd); 
and a sample xml file:
Code:
<markers>
<marker lat=
"58.0057450" lng="56.2401117"/>
<marker lat=
"58.0064167" lng="56.2426733"/>
<marker lat=<b>
""</b> lng=<b>""</b>/>
</markers>
if you send a request through the browser then everything is OK, but if the program is a string with empty values of lat and lng in the xml file, how can we solve this problem?
__________________
A&R Software Team
Reply With Quote
  #6 (permalink)  
Old 06-12-2009, 01:26 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

How do you send the data in the browser? As part of the URL?
If yes then you should use the default GET method instead of POST and just append the parameters to the URL.
__________________
Basic4android documentation
Reply With Quote
  #7 (permalink)  
Old 06-12-2009, 01:57 PM
Knows the basics
 
Join Date: Aug 2008
Location: Russia, Perm
Posts: 70
Send a message via ICQ to Aspire89
Default

Replaced POST to GET and it works, once again, thank you.
__________________
A&R Software Team
Reply With Quote
  #8 (permalink)  
Old 08-22-2009, 02:40 PM
Knows the basics
 
Join Date: Aug 2008
Location: Russia, Perm
Posts: 70
Send a message via ICQ to Aspire89
Default

I use request.New3(url, User, Pass), and requires an additional change code page encoding. How can this be done? Tried through door.dll library, but fails.

Thanks.
__________________
A&R Software Team
Reply With Quote
  #9 (permalink)  
Old 08-22-2009, 04:11 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

The code page parameter is not used. It was used in the one of the previous versions but currently it has no effect at all.
You should set the encoding of the BinaryFile object to the required encoding.
__________________
Basic4android documentation
Reply With Quote
  #10 (permalink)  
Old 01-05-2010, 07:28 AM
Junior Member
 
Join Date: Sep 2009
Posts: 47
Default

Can I request to have domain name in the SetProxy? I noted I need to customize the dll when connect from company network which used some sort of AD authentication. Thanks.

public void SetProxy3(string Host, int PortNumber, bool BypassOnLocal, string Username, string Password, string Domain)
{
WebProxy w = new WebProxy(Host, PortNumber);
w.Credentials = new NetworkCredential(Username, Password, Domain);
w.BypassProxyOnLocal = BypassOnLocal;
GlobalProxySelection.Select = w;
}
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:23 AM.


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