http.post() 요청을 직접 수행하는 데 문제가 있습니다. 루아 어가있는 ESP8266을 기반으로 NodeMCU에서 API 요청을 수행하려고합니다. 내가 만난 첫 번째 문제는 "HTTPS 주소의 일반 HTTP"입니다. 지금은 "악성 토큰"이라고 말하면서, 그가 내 게시물 매개 변수를받지 못했음을 의미합니다.주소 뒤에? key = value & key = value를 사용하여 올바른 HTTP Post 요청을 만드는 방법
어떻게 정확해야합니까?
http.post("http://www.2level.1level/api.php","Content-Type: text/plain","token=mytokenhere&arg1=argumentforrequest",
function(code, data)
if (code < 0) then
print("HTTP request failed")
else
print(code, data)
end
end)
일반적으로 나는 GMod Lua를 사용하여 요청합니다. 코드는 간단있을 것입니다 :
http.Post("https://www.2level.1level/api.php",{token=mytokenhere,arg1=argumentforrequest},function(txt) end,function(txt) end)
================== 업데이트. 나는 내 자신의 코드를 만들었다.
function ghttp.Post(url, parameters, onSuccess, onFailure, headers)
local add = ""
if parameters then
local temp = {}
for k,v in pairs(parameters) do
table.insert(temp,ghttp.encode(k).."="..ghttp.encode(v))
end
add = "?"..table.concat(temp, "&")
end
http.post(url..add,"Content-Type: application/json\r\n"..(headers or ""),"",function(code, data)
if (code < 0) then
if onFailure then onFailure() end
else
if onSuccess then onSuccess(code,data) end
end
end)
end
하지만 지금은 새로운 문제를 가지고 : 일부 API의 요청에 HTTPS 만 연결합니다.
콘텐츠 유형이 text/plain이 아닙니다. –
해결할 수 있습니까? –