luasocket: Using http.request for POST request with BODY lead to timeout

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

luasocket: Using http.request for POST request with BODY lead to timeout

Wilhelm Pflüger
I try to use socket.http to send a SOAP message with POST in the body of
http.
See the following code:

local http = require("socket.http")

    body = [[<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ViewLogStatus
xmlns="http://www.thermo.com/informatics/xmlns/limswebservice" />
  </soap:Body>
</soap:Envelope>]]

local r,c,h = http.request{
    url = "http://xx/LimsWebService/default.asmx?op=ViewLogStatus",
    sink = ltn12.sink.file(io.open("test.out", "w")),
    headers = {
      ["Content-Type"] = "text/xml; charset=utf-8",
      ["content-length"] = tostring(body:len()),

["SOAPAction"]="\"http://www.thermo.com/informatics/xmlns/limswebservice/ViewLogStatus\""
        ["Host"] = "xx",
        },
    body = ltn12.source.string(body),
    method = "POST"
}

This leads always to a timeout and using a wireshark i can see the http
headers only - no body.

I tried a 'trick' to insert the body in the header telegram:

local r,c,h = http.request{
    url = "http://xx/LimsWebService/default.asmx?op=ViewLogStatus",
    sink = ltn12.sink.file(io.open("test.out", "w")),
    headers = {
        ["Content-Type"] = "text/xml; charset=utf-8",
        ["content-length"] = tostring(body:len()+4),
        ["SOAPAction"] =
"\"http://www.thermo.com/informatics/xmlns/limswebservice/ViewLogStatus
\"",
        ["Host"] = "xx\r\n\r\n\r\n"..body
        },
    method = "POST"
}


This works (more or less) and the server is responding.

Do I misunderstand something with the first (the 'official') version?
Is there a known bug?

Any help is welcome.

Wilhelm




Reply | Threaded
Open this post in threaded view
|

Re: luasocket: Using http.request for POST request with BODY lead to timeout

Ashwin Hirschi

> I try to use socket.http to send a SOAP message with POST in the body of  
> http.

Try setting the request "source" key instead of using "body".

Also, the timeout happens because your content-length promises the server  
more is on the way [but no body is ever sent].

Ashwin.

Reply | Threaded
Open this post in threaded view
|

Aw: Re: luasocket: Using http.request for POST request with BODY lead to timeout

Wilhelm Pflüger
With 'source' instead of 'body' it works.
I could hug you. Such a silly RTFM-error.

Thank you very much.

Wilhelm

Gesendet: Freitag, 25. Mai 2012 um 00:59 Uhr
Von: "Ashwin Hirschi" <[hidden email]>
An: "Lua mailing list" <[hidden email]>
Betreff: Re: luasocket: Using http.request for POST request with BODY lead to timeout

> I try to use socket.http to send a SOAP message with POST in the body of
> http.

Try setting the request "source" key instead of using "body".

Also, the timeout happens because your content-length promises the server
more is on the way [but no body is ever sent].

Ashwin.


  

Ihr WEB.DE Postfach immer dabei: die kostenlose WEB.DE Mail App für iPhone und Android.   
https://produkte.web.de/freemail_mobile_startseite/