POST request to Pastebin with lua

nodobra

Новичок
Автор темы
6
0
Hey. I'm trying to upload some text to pastebin using Moonloader. The thing is no matter what I do, pastebin returns: text = "Bad API request, invalid api_dev_key.

I was trying to achieve the same thing by using a terminal and curl. It works just fine there, so the key I'm using is correct.

The code I'm trying to run:
Lua:
local copas = require 'copas'
local http = require 'copas.http'
local requests = require 'requests'
requests.http_socket, requests.https_socket = http, http
local inspect = require 'inspect'

function httpRequest(method, request, args, handler)
    if not copas.running then
        copas.running = true
        lua_thread.create(function()
            wait(0)
            while not copas.finished() do
                local ok, err = copas.step(0)
                if ok == nil then error(err) end
                wait(0)
            end
            copas.running = false
        end)
    end

    if handler then
        return copas.addthread(function(m, r, a, h)
            copas.setErrorHandler(function(err) h(nil, err) end)
            h(requests.request(m, r, a))
        end, method, request, args, handler)
    else
        local results
        local thread = copas.addthread(function(m, r, a)
            copas.setErrorHandler(function(err) results = {nil, err} end)
            results = table.pack(requests.request(m, r, a))
        end, method, request, args)
        while coroutine.status(thread) ~= 'dead' do wait(0) end
        return table.unpack(results)
    end
end

key = 'mykey'

lua_thread.create(function()
  wait(1000)
  local response, err = httpRequest('POST', { url = 'https://pastebin.com/api/api_post.php', data={api_dev_key = key}})
  if err then error(err) end
    local json_data = response.json()
    print(inspect(response))
end)
Pastebin also requires api_option and api_paste_code but without them it should give me a different message anyway.
It doesn't matter if I add those 2 arguments to the POST request, because it doesn't change the response.

I know there are lua libraries such as lua-curl, but I have no idea how to compile them for Windows and I think luarocks doesn't offer a way to compile .dll on linux. I've tried to force it but silly me, because it didn't work (duh).