【问题标题】:Add body to luasocket POST request with generic form?使用通用形式将正文添加到 luasocket POST 请求?
【发布时间】:2022-08-16 02:24:39
【问题描述】:

https://w3.impa.br/~diego/software/luasocket/http.html 开始,有两种方法可以发出请求,简单和通用。我已经让身体用简单的方法工作了。但是,当我将 LTN12 源添加到通用方法时,会向服务器发送一个空正文。

http.request(url [, body])

http.request{
  url = string,
  [sink = LTN12 sink,]
  [method = string,]
  [headers = header-table,]
  [source = LTN12 source],
  [step = LTN12 pump step,]
  [proxy = string,]
  [redirect = boolean,]
  [create = function]
}

这有效:

http.request(\"http://localhost:56218/sendState\", \"at=\" .. AT)

这不会:

    local reqbody = \"hi\"
    local respbody = {} 
    local  body, code, headers, status = http.request {
      url = \"http://localhost:56218/sendState\",
      source = ltn12.source.string(reqBody),
      headers = {
        [\"content-length\"] = string.len(reqbody)
      }
      sink = ltn12.sink.table(respbody)
  }

当我尝试在我的服务器中读取上述代码行的正文时,它是空的。我究竟做错了什么?

    标签: http post lua request luasocket


    【解决方案1】:

    你解决了吗?我有同样的问题

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-02
      相关资源
      最近更新 更多