B4A Library Http library v1.10

Status
Not open for further replies.
This update changes the way that bytes arrays are managed in HttpRequest.InitializePost2. This change allows HttpClient to retry and resend the data in case of IO errors. It makes POST calls more stable.
Some errors are now printed to the unfiltered log and give more information about the error.

Edit: The Response object which is passed to HttpClient_ResponseError is not consumed automatically. It allows you to read the message sent from the server.
However it also means that you are responsible to call Response.Release eventually.
Typical code should look like:
B4X:
Sub hc_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
    Log("Error: " & Reason & ", StatusCode: " & StatusCode)
    If Response <> Null Then
        Log(Response.GetString("UTF8"))
        Response.Release
    End If
End Sub
Installation instructions:
- Unzip the attached file.
- Copy both files to the internal libraries folder: C:\Program Files\Anywhere Software\Basic4android\Libraries
 

Attachments

  • HTTP.zip
    15.8 KB · Views: 1,034

Erel

B4X founder
Staff member
Licensed User
Longtime User
A new version (1.10) was uploaded to the first post. It fixes an issue related to the Response object not equals Null although it should be Null. This will cause a NullPointerException to be thrown when the string is retrieved.

There is also a new example of how to download a web page as a string in the manual: Basic4android - HTTP
 

batchfile

New Member
Licensed User
Longtime User
Non-Async Downloads

Is there any way I can just do:

Dim a as string
a = HttpClient.GetString("www.google.com")

?

It's just easier sometimes.

Also, I've noticed that it will crash if you queue more than 20 work items.
I did a quick loop to download some images and it gave me some error about a pool or queue, something like that. I don't have the exact error right now.
If there was a ConcurrentTasks property then we could just set one number and internally it would handle it a little nicer so we could just queue up all we want.

In my case i'd queue up and download about 50 thumbnail sizes images about 128x128 each. Each time an image is downloaded I add a listview item with the image and some text.
 

batchfile

New Member
Licensed User
Longtime User
This is what I would do in .net:
Dim result = My.Computer.Network.DownloadFile("SomeURL")
 

petri2000

Member
Licensed User
Longtime User
Java error adding HTTPUtils Service module

I have a simple app that is collecting user data and now I am trying to submit the data to a webservice. But once I add the modules HttpUtils & HttpUtilsService (Version 1.02) and try to compile (without even using anything from these modules) I get the following error (See below). Any Ideas? The HTTP Utils sample works fine. In the project I also have reference to the following libraries: HTTP 1.10, Phone 1.37, SQL 1.02, XMLSax 1.0, Animation 1.02 and Core 1.45

Any help appriciated. :sign0085:

Compiling code. 0.05
Generating R file. 0.00
Compiling generated Java code. Error
javac 1.6.0_21
src\com\animation\test\httputilsservice.java:54: cannot find symbol
symbol : class IntentWrapper
location: package anywheresoftware.b4a.objects
anywheresoftware.b4a.objects.IntentWrapper iw = new anywheresoftware.b4a.objects.IntentWrapper();
^
1 error

Some Additiona info: after trying to figure out what was wrong and tying to run the samples again i realised that the HTTPUtils samples do not work anymore!!!! Is this because I managed to break some library or? The same error message occurs as above.
 
Last edited:

petri2000

Member
Licensed User
Longtime User
Java error adding HTTPUtils Service module

I am using 1.60, registered version (of course)
I've Restarted (in case of any Windows issues, have win7 ultimate), I also uninstalled and reinstalled the Android SDK.

Cheers,

Petri
 

petri2000

Member
Licensed User
Longtime User
You are using an old version of Phone library which is not compatible with B4A v1.6. Make sure that there is no copy of Phone library in the additional libraries folder.

Thanks for the tip. I updated the Phone Library to 1.42 and made sure that there are no dublicates in the additional Library folder. However the same error remains when trying to run any app with reference to the httputils modules.
 

petri2000

Member
Licensed User
Longtime User
The version of the phone library should be 1.55. Reinstall Basic4android v1.6. It should include the updated library.

Thanks for the prompt response Erel... I followed your instructions uninstalled (and made sure the old libraries folders were deleted) and have now the updated version of the 1.55. Unfortunetly, exactly the same error occurs as previously. :BangHead: I am really hitting the wall here...
 

petri2000

Member
Licensed User
Longtime User
I basically given up and are creating the B4A in an virtual environment to start from scratch. After installing and trying to compile... I get the following message.

Compiling code. 0.14
Generating R file. 0.00
Compiling generated Java code. Error
javac 1.7.0
javac: target release 1.5 conflicts with default source release 1.7

I assume from the error message that Only 1.6 of the JDK is supported. Correct?
 

petri2000

Member
Licensed User
Longtime User
OK, I think I solved the issue! To make it easier for other that might have a similar issues. How I solved this... was the following steps....
1) I went in the IDE to the tools -> Configure paths -> and made the additional libraries option blank.
2) Run the samples -> all worked!
3) I went through and deleted any dublicates in the optional library path..

Voila! It worked! Leasons learnt! Do not dublicate libraries in the default library path and in the additional libray folder.

Maybe this could be a check implemented in a future versions of the IDE to check for dublicate versions of libs (as updated libs seems to be installed with new released of the IDE).

Cheers,

Petri
 

KY Leng

Active Member
Licensed User
Longtime User
Hi,

Do anyone here know how to use Http Post to send a request with the following procedure:
POST /glm/mmap HTTP/1.1
HOST: google.com
Content-Type: application/binary
Content-Length: 82
Connection: close
And the relevant string consists of 82 characters.

I know how to use Http with Url, but with these kind of requirement/procedure, I don't know.

Looking forward to hearing from you all soon,
 
Status
Not open for further replies.
Top