http.post()リクエストを自分で行うことに問題があります。 LUA言語の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ではありません。 –
これは解決済みとみなされますか? –