HTTPS запрос

Ademax

Новичок
Автор темы
7
1
Версия MoonLoader
.026-beta
Мне нужно отправить GET-запрос по защищенному каналу, но чет не работает. По http все работает.

Code:
copas = require 'copas'
http = require 'copas.http'

function httpRequest(request, body, handler) -- copas.http
    -- start polling task
    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
    -- do request
    if handler then
        return copas.addthread(function(r, b, h)
            copas.setErrorHandler(function(err) h(nil, err) end)
            h(http.request(r, b))
        end, request, body, handler)
    else
        local results
        local thread = copas.addthread(function(r, b)
            copas.setErrorHandler(function(err) results = {nil, err} end)
            results = table.pack(http.request(r, b))
        end, request, body)
        while coroutine.status(thread) ~= 'dead' do wait(0) end
        return table.unpack(results)
    end

function testRequest(userId, groupId, message)
    url = 'ссылка с параметрами'

    httpRequest(url, nil, function(response, code, headers, status)
        if response then
            print('Сервер принял запрос, ответ:' , response)
        else
            print('Произошла ошибка')
        end
    end)
end
 
Решение
Мне нужно отправить GET-запрос по защищенному каналу, но чет не работает. По http все работает.

Code:
copas = require 'copas'
http = require 'copas.http'

function httpRequest(request, body, handler) -- copas.http
    -- start polling task
    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
    -- do request
    if handler then
        return copas.addthread(function(r, b, h)
            copas.setErrorHandler(function(err) h(nil...

RedHolms

Известный
Проверенный
622
369
Мне нужно отправить GET-запрос по защищенному каналу, но чет не работает. По http все работает.

Code:
copas = require 'copas'
http = require 'copas.http'

function httpRequest(request, body, handler) -- copas.http
    -- start polling task
    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
    -- do request
    if handler then
        return copas.addthread(function(r, b, h)
            copas.setErrorHandler(function(err) h(nil, err) end)
            h(http.request(r, b))
        end, request, body, handler)
    else
        local results
        local thread = copas.addthread(function(r, b)
            copas.setErrorHandler(function(err) results = {nil, err} end)
            results = table.pack(http.request(r, b))
        end, request, body)
        while coroutine.status(thread) ~= 'dead' do wait(0) end
        return table.unpack(results)
    end

function testRequest(userId, groupId, message)
    url = 'ссылка с параметрами'

    httpRequest(url, nil, function(response, code, headers, status)
        if response then
            print('Сервер принял запрос, ответ:' , response)
        else
            print('Произошла ошибка')
        end
    end)
end
copas только на http, используй ssl:
Lua:
https = require 'ssl.https' -- Интерфейс такой-же, как и copas.http
 
  • Нравится
Реакции: Ademax

Похожие темы

  1. Ответы
    137
    Просмотры
    91K
  2. Ответы
    5
    Просмотры
    2K
  3. Ответы
    0
    Просмотры
    688
  4. Ответы
    1
    Просмотры
    409