Example of asynchttpPost using querystring

I'm trying to use querystring to pass paramters like:

try {
def postParams = [
uri: "http://192.168.10.236:8000/notify/1",
requestContentType: 'application/json',
contentType: 'application/json',
querystring: "type=info&title=From+GUI&tag=email",
body : ["body": "foo"]

    ]
  log.info postParams
  
    asynchttpPost('myCallbackMethod', postParams, "1"])
    
} catch(Exception e) {
  if(e.message.toString() != "OK"){
  	log.error e.message
      }
}

It works fine if I comment out the querystring option. I can capture the packet with wireshark and see it fine. When I add in the querystring option, I get no error in the log, but the http post never happens and no packets go over the network.

I'm just trying to figure out how to use it.

thanks
david

Super old message, but I thought I would reply because I was already troubleshooting some HTTP stuff and could give it a try.

You can fix it either of a couple of ways:

  • queryString has a capitalization error in your sample. However, note that I got an HTTP 408 error, not no traffic. Maybe something has changed or been fixed since your testing, though. I'm on hub platform version 2.2.1.115 as I write this.
  • use query instead with a map of the terms. I prefer this method because it's easier for me to not screw up the queryString.

Either of these worked for me:

queryString

def traceRandomCode(number)
{
    try
    {
        def postParams = 
            [
            uri: "https://postman-echo.com/post",
            requestContentType: 'application/json',
            contentType: 'application/json',
            queryString: "type=info&title=From+GUI&tag=email",
            body : ["body": "foo"]
            ]
        
        logDebug("$postParams")
        asynchttpPost('myCallbackMethod', postParams)
    }
    catch(Exception e)
    {
        if(e.message.toString() != "OK")
        {
            log.error e.message
        }
    }
}

def myCallbackMethod(response, data)
{
    logDebug("response.status = ${response.status}")
    if(!response.hasError())
    {
        logDebug("response.getData() = ${response.getData()}")
    }        
}

[dev:3544](http://10.0.0.4/logs#dev3544)2020-07-10 02:32:32.408 pm [debug](http://10.0.0.4/device/edit/3544)response.getData() = {"args":{"type":"info","title":"From GUI","tag":"email"},"data":{"body":"foo"},"files":{},"form":{},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-5f08c253-2ac58ce6f4e1437a447f8aba","content-length":"14","accept":"application/json","content-type":"application/json","user-agent":"Apache-HttpClient/4.5.2 (Java/1.8.0_181)","accept-encoding":"gzip,deflate"},"json":{"body":"foo"},"url":"https://postman-echo.com/post?type=info&title=From+GUI&tag=email"}

[dev:3544](http://10.0.0.4/logs#dev3544)2020-07-10 02:32:32.395 pm [debug](http://10.0.0.4/device/edit/3544)response.status = 200

[dev:3544](http://10.0.0.4/logs#dev3544)2020-07-10 02:32:32.003 pm [debug](http://10.0.0.4/device/edit/3544)[uri:https://postman-echo.com/post, requestContentType:application/json, contentType:application/json, queryString:type=info&title=From+GUI&tag=email, body:[body:foo]]

query

def traceRandomCode(number)
{
    try
    {
        def postParams = 
            [
            uri: "https://postman-echo.com/post",
            requestContentType: 'application/json',
            contentType: 'application/json',
            query: [type: "info", title: "From+GUI", tag: "email"],
            body : ["body": "foo"]
            ]
        
        logDebug("$postParams")
        asynchttpPost('myCallbackMethod', postParams)
    }
    catch(Exception e)
    {
        if(e.message.toString() != "OK")
        {
            log.error e.message
        }
    }
}

def myCallbackMethod(response, data)
{
    logDebug("response.status = ${response.status}")
    if(!response.hasError())
    {
        logDebug("response.getData() = ${response.getData()}")
    }        
}

[dev:3544](http://10.0.0.4/logs#dev3544)2020-07-10 02:34:51.800 pm [debug](http://10.0.0.4/device/edit/3544)response.getData() = {"args":{"type":"info","title":"From+GUI","tag":"email"},"data":{"body":"foo"},"files":{},"form":{},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-5f08c2de-7a96d9a321bb61b1c1f7e0fb","content-length":"14","accept":"application/json","content-type":"application/json","user-agent":"Apache-HttpClient/4.5.2 (Java/1.8.0_181)","accept-encoding":"gzip,deflate"},"json":{"body":"foo"},"url":"https://postman-echo.com/post?type=info&title=From%2BGUI&tag=email"}

[dev:3544](http://10.0.0.4/logs#dev3544)2020-07-10 02:34:51.780 pm [debug](http://10.0.0.4/device/edit/3544)response.status = 200

[dev:3544](http://10.0.0.4/logs#dev3544)2020-07-10 02:34:51.293 pm [debug](http://10.0.0.4/device/edit/3544)[uri:https://postman-echo.com/post, requestContentType:application/json, contentType:application/json, query:[type:info, title:From+GUI, tag:email], body:[body:foo]]

Download the Hubitat app