Json Decode after HTTPS Basic Authentication troubles

I’m using basic authentication to log in to my web service over https, however the variable output of r is only returning the value of 1, making json.decode ineffective. How do I perform basic authentication and return the json query after successfully authenticating? Thanks in advance. :smile:

local json = require("json")
local ssl = require( "plugin.openssl" )
local http = require('plugin_luasec_https')
local mime = require("mime")

local URL = "https://127.0.0.1/example/default/call/json/testing/"

local r, c = http.request {
		url = URL,
		headers = { authentication = "Basic " .. (mime.b64("username:passwd")) }
	} 
print(r)
print(c)

if r == nil then do
	end
else
	local data, pos, msg = json.decode(r)
end

Well I figured this out, so I’ll post my results for others.

local json = require("json")
local ssl = require( "plugin.openssl" )
local http = require('plugin_luasec_https')
local mime = require("mime")
local ltn12 = require("ltn12");

local URL = "https://127.0.0.1/default/call/json/testing/"


local username = "username"
local password = "passwd"

local request_t = {}
local res, c = http.request {
		url = URL,
		headers = {authentication = "Basic " .. (mime.b64(username ..":" .. password))},
		sink = ltn12.sink.table(request_t),
	} 
	
result_data = table.concat(request_t)
print(result_data)

if res == nil then do
	end
else
	local data, pos, msg = json.decode(result_data)
end

I was unable to authenticate with this code, but I was able to using the browser with the following:

https://username:passwd@127.0.0.1/default/call/json/testing/ 

So I assume there is still something wrong with my server configuration or code.