Only Post / Put requests support this method.

geewiztech

Member
Licensed User
Longtime User
I'm using the following code to retrieve some json

B4X:
Sub login()
    Dim job1 As HttpJob
    job1.Initialize("mcma.login", Main)
    Dim url As String
    Dim s As serverConn
    s.Initialize()
    url = "http://" & s.getServer("serverip") & ":" & s.getServer("port") & "/data.json"
    job1.Download2(url, Array As String("req", "login", "token", "", "MCMASESSIONID" , "", "username", s.getServer("userid"), "password", s.getServer("password")))
    job1.GetRequest.SetContentEncoding("application/json")
End Sub

and I get the following error

java.lang.RuntimeException: Only Post / Put requests support this method.

Any ideas ?
 

geewiztech

Member
Licensed User
Longtime User
I need to do a Get, but I need to send as application/json encoding otherwise I get:

API requests must have accept: application/json or text/javascript header.
 
Upvote 0

geewiztech

Member
Licensed User
Longtime User
I did thank you. I might be just being a bit thick, but I can't get my head round this.

This is the code I'm trying to emulate

B4X:
Public Function request(param As NameValueCollection) As String
        Dim result As String = ""
        Dim webclient As New WebClientEx(webcookie)
        webclient.Headers.Add("Content-Type", "application/json")
        webclient.Headers.Add("Accept", "application/json")
        webclient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)")
        Dim response As Byte() = webclient.DownloadData("http://" & ip & ":" & port & "/data.json" & "?" & param.ToString())
        result = webclient.Encoding.GetString(response)
        log(result)
        Return result
    End Function
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…