Forum Discussion

john_124672's avatar
john_124672
Icon for Nimbostratus rankNimbostratus
Feb 21, 2018

irule sideband connection to make external POST call to a service

Hi, I am trying to send a POST request to service from an irule. irule will check for certain headers in the request, extract them and try to make a call out using a sideband connection. I was able to make a GET request but having no luck trying to find the magic combination for POST. Docs on sideband connection seems very limited so here i am asking it here.

set data "POST /checkUser/[URI::encode $myUsername] HTTP/1.1\r\nHost: $authServiceWIP\r\nContent-Type: application/json\r\n\r\n\{ \"env\" : \"$groupEnv\", \"password\" : \"[URI::encode $myPassword]\" \}"

Snippet above has variables that are holding valid values. I replaced them with the hard-coded values but it seems to not make a difference from works/not works perspective.

When I send this data to call the service, I am getting :

Required request body is missing: as an error message from the backend service in the received_bytes.

So it seems like there is something that causes the request payload, which is simple JSON object, not being included.

I've tried countless things and had no luck so far.

One thing is that when I changed the variables to hard-coded values, for whatever reason not having the variable $authServiceWIP variable makes the error code shorter with just "http 400 connection closed 0". When i include this variable instead of its hardcoded value, i see the longer error message where the backend service is actually replying with an error message and response headers that the Request Body is missing.

I can call this service and POST to it from various other tools like curl, rest/devtools.

Any ideas?

Thanks

4 Replies

  • Mick's avatar
    Mick
    Icon for Altocumulus rankAltocumulus

    Hi John

     

    Did you get this working? i'm facing the same issue, wondering if you could help out if you had any luck

    Cheers

    Mick

  • Look into using iRuleLX instead of Sideband connections much easier.

     

    Sure someone has a link to a code share....

  • Hi John,

    I found the same issue.

    In my case the problem was the Content-Lenght and I resolved it in this way:

    I have created a JSON string and I have counted the length of it

     

    set json_data "\{ \"ipAddress\" : \"$client_ip\", \"userAgent\" : \"$user_browser\" \}"
    set cnt_length [string length $json_data]

     

    After that I have populated the POST request

     

    set data "POST /test HTTP/1.1\r\nHost: www.test-acme.local\r\nAuthorization: Basic cGlwcG86cGx1dG8=\r\nContent-type: application/json\r\nContent-Length: $cnt_length\r\n\r\n$json_data"
    set send_info [send -timeout 3000 -status send_status $conn $data]

     

    I hope this help you.

    Sorry for my terrible english