B4J Question HTTP Service Authentication

Pedro Caldeira

Active Member
Licensed User
Longtime User
I have to authenticace to a Web Service, with a custom header, but can't get the Job1.GetRequest.SetHeader to work
I always get :
Error description: Unknown type: anywheresoftware.b4a.http.HttpClientWrapper.HttpUriRequestWrapper
Are you missing a library reference?
What library do you guys use ?
I am doing a NON-UI App, by the way.
 

OliverA

Expert
Licensed User
Longtime User
add the okHttp (version: 1.20) library in the libraries manager.
 
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
You mean jOkHttpUtils2 ? I have the 2.40 Version.
I can use the Job1.GetRequest, just not the Job1.GetRequest.SetHeader
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
No, OkHttp ->

upload_2017-9-26_14-36-21.png
<--------- OkHttp

You need both. OkHttp "enables" the SetHeader method
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
It’s part of the “standard” libraries that are installed with B4J. Could be that you have to scroll down in your library list (just a guess) to see it.
 
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
I always get error 404 while posting.
According to the application's manual I should get a nonce

I am using this in B4J

B4X:
Dim WrstServer As String = "http://192.168.0.202:8080"
Dim WinRESTKey As String ="u7crun6Qk4g4z0qxJRAWGA=="
Dim http as httpjob

http.Initialize("WinRestConnection",Me)
http.Username = "username"
http.Password = "password"
http.PostString(WrstServer, Block2Send)
http.GetRequest.SetContentEncoding("text/html")

to mimic this curl command:

B4X:
curl --user username:password
-H "Content-type: text/html"
-v -X POST http://localhost:8080/RPC3 -d
'<?xml version="1.0 ?>
<methodCall>
<methodName>RequestSErver.GetTableState</methodName>
<params>
<param>
<value><i4>15</i4></value>
</param>
</params>
</methodCall>'


I should get an Answer with an Unauthorized error 401 and a nonce to autenticate the next request.
But I only get the 404 Not Found Error
 
Upvote 0
Top