FAQ
I can't seem to find how to make a post request with post data, and custom
set headers.
The data is in json form such as:
{
channel : { 1 , 2 }
data : { 'hello world' }
}

I can make post requests, and make requests with custom headers, but can't
seem to do both.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Jesse McNelis at Apr 22, 2013 at 12:06 am

    On Mon, Apr 22, 2013 at 9:56 AM, wrote:

    I can't seem to find how to make a post request with post data, and custom
    set headers.
    The data is in json form such as:
    {
    channel : { 1 , 2 }
    data : { 'hello world' }
    }

    I can make post requests, and make requests with custom headers, but can't
    seem to do both.
    Put your post data in an io.Reader of some kind and pass it in to create a
    new request
    http://golang.org/pkg/net/http/#NewRequest

    Each request has a 'Header' field you can modify.
    http://golang.org/pkg/net/http/#Header

    Send the request using a client
    http://golang.org/pkg/net/http/#Client

    The http pkg has a 'DefaultClient' variable defined which you can use.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Johnalan Simmons at Apr 22, 2013 at 12:35 am
    Is there a suggestion for an io.Reader, im lost on that account
    On Sunday, April 21, 2013 7:56:58 PM UTC-4, [email protected] wrote:

    I can't seem to find how to make a post request with post data, and custom
    set headers.
    The data is in json form such as:
    {
    channel : { 1 , 2 }
    data : { 'hello world' }
    }

    I can make post requests, and make requests with custom headers, but can't
    seem to do both.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jesse McNelis at Apr 22, 2013 at 12:44 am

    On Mon, Apr 22, 2013 at 10:35 AM, wrote:

    Is there a suggestion for an io.Reader, im lost on that account

    There are lots of io.Readers. Any type that satisfies the
    http://golang.org/pkg/io/#Reader interface.
    If you have a string, http://golang.org/pkg/strings/#NewReader will get you
    an io.Reader for that string.
    A []byte then http://golang.org/pkg/bytes/#NewReader<http://golang.org/pkg/strings/#NewReader>
    .
    Files, network connections, buffers etc. are all io.Readers.


    =====================
    http://jessta.id.au

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Johnalan Simmons at Apr 22, 2013 at 1:07 am
    If I were to just pass the json string into string NewReader, would that be
    sufficient, or would that approach only work for say urlenoded data?

    post_data := strings.NewReader(jsonString)
    req := http.NewRequest("POST", "www.example.com", post_data)

    // ... add header stuff

    would this be sufficient
    On Sunday, April 21, 2013 7:56:58 PM UTC-4, [email protected] wrote:

    I can't seem to find how to make a post request with post data, and custom
    set headers.
    The data is in json form such as:
    {
    channel : { 1 , 2 }
    data : { 'hello world' }
    }

    I can make post requests, and make requests with custom headers, but can't
    seem to do both.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Johnalan Simmons at Apr 22, 2013 at 2:37 am
    Thanks, all is well!
    On Sunday, April 21, 2013 7:56:58 PM UTC-4, [email protected] wrote:

    I can't seem to find how to make a post request with post data, and custom
    set headers.
    The data is in json form such as:
    {
    channel : { 1 , 2 }
    data : { 'hello world' }
    }

    I can make post requests, and make requests with custom headers, but can't
    seem to do both.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 21, '13 at 11:57p
activeApr 22, '13 at 2:37a
posts6
users2
websitegolang.org

2 users in discussion

Johnalan Simmons: 4 posts Jesse McNelis: 2 posts

People

Translate

site design / logo © 2023 Grokbase