This topic contains 4 replies, has 3 voices, and was last updated by  MGreenwald 1 year, 10 months ago.

Http Rest Post Request Slow Response

  • I have the following function

    local function PostRequest(a, a1, a2, a3, a4, a5)
    local URL = string.format('%s/Action?args1=%s&args2=%s&args3=%s&args4=%s&args5=%s', a, a1, a2, a3, a4, a5)
    
    local header = {["Content-type"] = "application/json", ["User-Agent"] = "Iguana"}
    local jResponse, statusCode = net.http.post{url=URL, live=true, body=nil, headers=header} 
    end

    When I execute the post request this way it operates as expected, web service call returns in no time. But if I change the function to

    local function PostRequest(a, a1, a2, a3, a4, a5)
    local URL = string.format('%s/Action?args1=%s&args2=%s&args3=%s&args4=%s&args5=%s', a, a1, a2, a3, a4, a5)
    
    local header = {["Content-type"] = "application/json", ["User-Agent"] = "Iguana"}
    local jResponse, statusCode = net.http.post{url=string.gsub(string.gsub(URL, ' ', '%%20'), '+', '%%2B'), live=true, body=nil, headers=header}
    end

    The web service call will consistently take 8 – 10 seconds. All the second version of the function does is do a type of “html encode” string replacement. The URL is never very long, maybe 250 characters max. It does not make sense to me why doing the string replacement is having such a large impact.

    Is there anything I can do to be able to encode the URL but not sacrifice so much time?

    Thanks!

    Have you looked into using the parameters argument rather than building your own with net.http.post()?

    local function PostRequest(a, a1, a2, a3, a4, a5)
        local URL = string.format('%s/Action', a)
        local postparams = {args1=a1, args2=a2, args3=a3, args4=a4, args5=a5}
        local header = {["Content-type"] = "application/json", ["User-Agent"] = "Iguana"}
        local jResponse, statusCode = net.http.post{url=URL, parameters=postparams, live=true, body=nil, headers=header}
    end
    

    Jeff Drumm ◊ VP and COO ◊ HICG, LLC. ◊ http://www.hicgrp.com

    I wonder if you will have same result when you try with less ambitious syntax – to use filter.uri.enc() outside of net.http.post{} parameters; and to use the result of filter.uri.enc() with net.http.post{} parameters.

    Hi Lev,

    Per the API documentation, the parameters option performs uri encoding. Of course you may not have seen my post prior to your posting 🙂

    Jeff Drumm ◊ VP and COO ◊ HICG, LLC. ◊ http://www.hicgrp.com

    Hi Guys,
    It turned out to be something with either the web server or network. When I went to implement the suggested changes I tried the methods I mentioned above one last time but today both are executing in about the same time, as I expected to originally. Strange considering I restarted web server yesterday to see if that would clear the block.

    Thanks for the suggestions!

You must be logged in to reply to this topic.