Skip to content

Trouble sending JSON post data to a service #391

@amitsaha

Description

@amitsaha

Hi all, posted my query about having trouble sending JSON body in a POST request here. Wondering if I am doing something wrong here or perhaps a hidden actual issue here?

Summarized the problem here:

I am just writing a simple "API Gateway" using the different go-kit libraries. The current code is at https://github.com/amitsaha/apigatewaydemo/blob/master/src/apigateway/main.go

This gateway currently routes HTTP POST requests to 127.0.0.1:8000/projects to another service I have running (a Python web app on port 5000) which I discover via consul. The routing happens correctly, however, I am not able to send the JSON body through to my web app. The encodeJSONRequest() function is the one which is supposed to do this correctly: https://github.com/amitsaha/apigatewaydemo/blob/master/src/apigateway/main.go#L48 however it doesn't seem to be working.

Example request:

$ http POST 127.0.0.1:8000/projects/ Auth-Header-V1:123 title=MyProject121

I modified the httpclient to dump the request it is sending and this is what it looks like:

"POST /create HTTP/1.1\r\nHost: 127.0.0.1:5000\r\nUser-Agent: Go-http-client/1.1\r\nTransfer-Encoding: chunked\r\nAccept-Encoding: gzip\r\n\r\n1\r\n{\r\n18\r\n\"title\":\"MyProject121\"}\n\r\n0\r\n\r\n"

It seems like the body is not being encoded correctly?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions