Android Question post requests in b4a

king_mkv

Member
Hello my friends
I want to send a request in Basic Four Android and show a response to the user, depending on the response I get from the server.
I used to work with Python, and there it was very easy to use a site to convert curls to Python commands. Is there a way I can request a server with a header, cookie and body request?
like in python :

headers = {
'Host': 'hostname',
'User-Agent': 'UnityPlayer/2019.3.4f1 (UnityWebRequest/1.0, libcurl/7.52.0-DEV)',
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate',
'Content-Type': 'application/json',
'AUTHORIZATION': self.password,
'X-Unity-Version': '2019.3.4f1',
'Content-Length': '36',
'Expect': '100-continue',
'Connection': 'close',
}

json_data = {
'key': 'key',
'value': 1,
}

requests.put('http://hostname/api/Game/user/achievement', headers=headers, json=json_data, verify=False)


@Erel
 
Solution
Please don't do it.

I want to send a request in Basic Four Android
B4A

B4X:
Dim j As HttpJob
j.Initialize("", Me)
Dim m As Map = CreateMap("key": "key", "value": 1)
j.PostString("link", m.As(JSON).ToCompactString)
j.GetRequest.SetContentType("application/json")
j.GetRequest.SetHeader("AUTHORIZATION", password)
Wait For (j) JobDone (j As HttpJob)
If j.Success Then
 Log(j.GetString)
End If
j.Release

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please don't do it.

I want to send a request in Basic Four Android
B4A

B4X:
Dim j As HttpJob
j.Initialize("", Me)
Dim m As Map = CreateMap("key": "key", "value": 1)
j.PostString("link", m.As(JSON).ToCompactString)
j.GetRequest.SetContentType("application/json")
j.GetRequest.SetHeader("AUTHORIZATION", password)
Wait For (j) JobDone (j As HttpJob)
If j.Success Then
 Log(j.GetString)
End If
j.Release
 
Upvote 2
Solution

king_mkv

Member
Please don't do it.


B4A

B4X:
Dim j As HttpJob
j.Initialize("", Me)
Dim m As Map = CreateMap("key": "key", "value": 1)
j.PostString("link", m.As(JSON).ToCompactString)
j.GetRequest.SetContentType("application/json")
j.GetRequest.SetHeader("AUTHORIZATION", password)
Wait For (j) JobDone (j As HttpJob)
If j.Success Then
 Log(j.GetString)
End If
j.Release
Thank you very much
Now, if I want to have the response I receive from the server in the form of a dictionary that I can access by giving the key name, what should I do?

for example :
dim a as string = '{"key":"value"}
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top