Android Question Rest API - Post works..... Get do not work? Please give me a hint!

Licht2002

Member
Licensed User
Longtime User
Hello Friends,

i working on a App with the a (Rest-)API.

First i have to get the Token with an POST:

B4X:
Sub Hole_Token
    job1.Initialize("Job1", Me)
    Dim objMap As Map: objMap.Initialize
     objMap.Put("password","123")
    objMap.Put("serialNumber","1234567890")
    objMap.Put("username","abc")
    Dim objJSon As JSONGenerator: objJSon.Initialize(objMap)
     Log(objJSon.ToPrettyString(2))
     job1.PostString("https://192.168.178.41:8443/session", objJSon.ToPrettyString(2))
End Sub

The Job get the new Token = OK!

But now i have to send a GET with Json and the Token:

In the Docomentation it looks like this:

METHOD: GET

URL: https://192.168.178.41:8443/group/set?idx=1&onoff=1

HEADER: { “Content-Type“ : “application/json“;
“authorization“: " 1234567890 "}


My Code:

B4X:
Sub Group1
    job2.Initialize("Job2", Me)
    Dim objMap As Map: objMap.Initialize
    objMap.Put("Content-Type","application/json")
    objMap.Put("Authorization",Token_String)
    Dim objJSon As JSONGenerator: objJSon.Initialize(objMap)
     Log(objJSon.ToPrettyString(2))
     job2.PostString("https://192.168.178.41:8443/group/set?idx=1&onoff=1", objJSon.ToPrettyString(2))
End Sub

do not work! -> Error: Method Not Allowed

How do i code a correct GET with a Header incl. Content-Type an Authorization....?

Thanks for your HELP!

Greetings Tom
 

sorex

Expert
Licensed User
Longtime User
you need to set the headers after initiating the download

B4X:
dlj.Download("https://192.168.178.41:8443/group/set?idx=1&onoff=1")
dlj.GetRequest.SetHeader("authorization", "75179816xxxxxxxxxx462229278169")
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
use job.download
Set header after the job.download
You need headers for Content-Type and authorization.

Search forum for examples.
 
Upvote 0
Top