Android Question Want to upload JSON data to server by using Http POST command?

jobykpaul

Member
Licensed User
Longtime User
Hi
I have to upload data to the server by using http POST request and data format is JOSN string. I follow the below code...

Dim Map1 As Map
Map1.Initialize
Dim JSONGenerator As JSONGenerator
Dim JSONstring As String
Map1.put("username","user1")
Map1.put("password","abcdef")
JSONGenerator.Initialize(Map1)

Dim j As HttpJob
j.Initialize("", Me)
j.PostString("http://54.385.735.10/mobility/api/login",JSONGenerator.ToString)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Msgbox(j.GetString,"")
endif


The JSON string is showing in the correct format.
When we try from the app, the response from the server is blank, but the same i tried from online Http POST tool it is working. Please help me to solve the issue.

Thank You
 

DonManfred

Expert
Licensed User
Longtime User
Please use [CODE]code here...[/CODE] tags when posting code.

You prrobably need to set a correct contenttype

B4X:
j.PostString(...)
j.GetRequest.SetContentType("application/json")' The line AFTER poststring....
 
Last edited:
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
You need to set the ContentType for JSON.
Add
B4X:
j.GetRequest.SetContentType("application/json")
after j.PostString

EDIT: I was too slow to beat DonManfred…
 
Upvote 0

jobykpaul

Member
Licensed User
Longtime User

Thank You for your promt reply it solve the issue when i add contenttype. Also i was use the old http library too....
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…