Quantcast

Making an HTTP POST in Groovy From Grails (Groovy Recipies)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Making an HTTP POST in Groovy From Grails (Groovy Recipies)

krusek
I am trying the code obtained from Chapter 9 Web Services from Groovy Recipes and I am getting the following error.

No signature of method: java.io.OutputStreamWriter.writer() is applicable for values: [n=20&vf=pdf&p=groovy+grails]

Here is the code:
        def queryString = []
        queryString << "n=" + URLEncoder.encode("20")
        queryString << "vf=" + URLEncoder.encode("pdf")
        queryString << "p=" + URLEncoder.encode("groovy grails")

        def url = new URL("http://search.yahoo.com/search")
        def connection = url.openConnection()
        connection.setRequestMethod("POST")
       
        connection.doOutput = true
        Writer writer = new OutputStreamWriter(connection.outputStream)
        writer.writer(queryString.join("&"))
        writer.flush()
        writer.close()
        connection.connect()
        println connection.content.text

Can someone help me determine what is wrong?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Making an HTTP POST in Groovy From Grails (Groovy Recipies)

pronto_mike
I think it might be the following line:

       writer.writer(queryString.join("&"))

I think it is suppose to be:

       writer.write(queryString.join("&"))


-Mike

On Fri, Nov 13, 2009 at 12:21 AM, krusek <[hidden email]> wrote:

>
> I am trying the code obtained from Chapter 9 Web Services from Groovy Recipes
> and I am getting the following error.
>
> No signature of method: java.io.OutputStreamWriter.writer() is applicable
> for values: [n=20&vf=pdf&p=groovy+grails]
>
> Here is the code:
>        def queryString = []
>        queryString << "n=" + URLEncoder.encode("20")
>        queryString << "vf=" + URLEncoder.encode("pdf")
>        queryString << "p=" + URLEncoder.encode("groovy grails")
>
>        def url = new URL("http://search.yahoo.com/search")
>        def connection = url.openConnection()
>        connection.setRequestMethod("POST")
>
>        connection.doOutput = true
>        Writer writer = new OutputStreamWriter(connection.outputStream)
>        writer.writer(queryString.join("&"))
>        writer.flush()
>        writer.close()
>        connection.connect()
>        println connection.content.text
>
> Can someone help me determine what is wrong?
> --
> View this message in context: http://old.nabble.com/Making-an-HTTP-POST-in-Groovy-From-Grails-%28Groovy-Recipies%29-tp26332381p26332381.html
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Making an HTTP POST in Groovy From Grails (Groovy Recipies)

krusek
krusek wrote
Yes,  That was it!  

Your awesome and so is this forum!
Michael Masters wrote
I think it might be the following line:

       writer.writer(queryString.join("&"))

I think it is suppose to be:

       writer.write(queryString.join("&"))


-Mike

On Fri, Nov 13, 2009 at 12:21 AM, krusek <krusek@comcast.net> wrote:
>
> I am trying the code obtained from Chapter 9 Web Services from Groovy Recipes
> and I am getting the following error.
>
> No signature of method: java.io.OutputStreamWriter.writer() is applicable
> for values: [n=20&vf=pdf&p=groovy+grails]
>
> Here is the code:
>        def queryString = []
>        queryString << "n=" + URLEncoder.encode("20")
>        queryString << "vf=" + URLEncoder.encode("pdf")
>        queryString << "p=" + URLEncoder.encode("groovy grails")
>
>        def url = new URL("http://search.yahoo.com/search")
>        def connection = url.openConnection()
>        connection.setRequestMethod("POST")
>
>        connection.doOutput = true
>        Writer writer = new OutputStreamWriter(connection.outputStream)
>        writer.writer(queryString.join("&"))
>        writer.flush()
>        writer.close()
>        connection.connect()
>        println connection.content.text
>
> Can someone help me determine what is wrong?
> --
> View this message in context: http://old.nabble.com/Making-an-HTTP-POST-in-Groovy-From-Grails-%28Groovy-Recipies%29-tp26332381p26332381.html
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Making an HTTP POST in Groovy From Grails (Groovy Recipies)

Matthew.Lachman
FYI, you can also accomplish the following:

        URLEncoder.encode("20")

Like this:

        "20".encodeAsURL()

See here for the relevant documentation: http://grails.org/doc/1.1.x/guide/single.html#11.2%20Encoding%20and%20Decoding%20Objects

Matt

-----Original Message-----
From: krusek [mailto:[hidden email]]
Sent: Friday, November 13, 2009 2:45 AM
To: [hidden email]
Subject: Re: [grails-user] Making an HTTP POST in Groovy From Grails (Groovy Recipies)



krusek wrote:
>
> Yes,  That was it!  
>
> Your awesome and so is this forum!
>
>

Michael Masters wrote:

>
> I think it might be the following line:
>
>        writer.writer(queryString.join("&"))
>
> I think it is suppose to be:
>
>        writer.write(queryString.join("&"))
>
>
> -Mike
>
> On Fri, Nov 13, 2009 at 12:21 AM, krusek <[hidden email]> wrote:
>>
>> I am trying the code obtained from Chapter 9 Web Services from Groovy
>> Recipes
>> and I am getting the following error.
>>
>> No signature of method: java.io.OutputStreamWriter.writer() is applicable
>> for values: [n=20&vf=pdf&p=groovy+grails]
>>
>> Here is the code:
>>        def queryString = []
>>        queryString << "n=" + URLEncoder.encode("20")
>>        queryString << "vf=" + URLEncoder.encode("pdf")
>>        queryString << "p=" + URLEncoder.encode("groovy grails")
>>
>>        def url = new URL("http://search.yahoo.com/search")
>>        def connection = url.openConnection()
>>        connection.setRequestMethod("POST")
>>
>>        connection.doOutput = true
>>        Writer writer = new OutputStreamWriter(connection.outputStream)
>>        writer.writer(queryString.join("&"))
>>        writer.flush()
>>        writer.close()
>>        connection.connect()
>>        println connection.content.text
>>
>> Can someone help me determine what is wrong?
>> --
>> View this message in context:
>> http://old.nabble.com/Making-an-HTTP-POST-in-Groovy-From-Grails-%28Groovy-Recipies%29-tp26332381p26332381.html
>> Sent from the grails - user mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>
>

--
View this message in context: http://old.nabble.com/Making-an-HTTP-POST-in-Groovy-From-Grails-%28Groovy-Recipies%29-tp26332381p26332598.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Making an HTTP POST in Groovy From Grails (Groovy Recipies)

Tom Nichols
<shameless self-promotion>
You can also use HTTPBuilder to easily POST data to other web servers
from Grails.  Then you don't have to muck around encoding the post
body yourself.  See:
http://groovy.codehaus.org/modules/http-builder/doc/post.html
</shameless self-promotion>

2009/11/13 Matthew.Lachman <[hidden email]>:

> FYI, you can also accomplish the following:
>
>        URLEncoder.encode("20")
>
> Like this:
>
>        "20".encodeAsURL()
>
> See here for the relevant documentation: http://grails.org/doc/1.1.x/guide/single.html#11.2%20Encoding%20and%20Decoding%20Objects
>
> Matt
>
> -----Original Message-----
> From: krusek [mailto:[hidden email]]
> Sent: Friday, November 13, 2009 2:45 AM
> To: [hidden email]
> Subject: Re: [grails-user] Making an HTTP POST in Groovy From Grails (Groovy Recipies)
>
>
>
> krusek wrote:
>>
>> Yes,  That was it!
>>
>> Your awesome and so is this forum!
>>
>>
>
> Michael Masters wrote:
>>
>> I think it might be the following line:
>>
>>        writer.writer(queryString.join("&"))
>>
>> I think it is suppose to be:
>>
>>        writer.write(queryString.join("&"))
>>
>>
>> -Mike
>>
>> On Fri, Nov 13, 2009 at 12:21 AM, krusek <[hidden email]> wrote:
>>>
>>> I am trying the code obtained from Chapter 9 Web Services from Groovy
>>> Recipes
>>> and I am getting the following error.
>>>
>>> No signature of method: java.io.OutputStreamWriter.writer() is applicable
>>> for values: [n=20&vf=pdf&p=groovy+grails]
>>>
>>> Here is the code:
>>>        def queryString = []
>>>        queryString << "n=" + URLEncoder.encode("20")
>>>        queryString << "vf=" + URLEncoder.encode("pdf")
>>>        queryString << "p=" + URLEncoder.encode("groovy grails")
>>>
>>>        def url = new URL("http://search.yahoo.com/search")
>>>        def connection = url.openConnection()
>>>        connection.setRequestMethod("POST")
>>>
>>>        connection.doOutput = true
>>>        Writer writer = new OutputStreamWriter(connection.outputStream)
>>>        writer.writer(queryString.join("&"))
>>>        writer.flush()
>>>        writer.close()
>>>        connection.connect()
>>>        println connection.content.text
>>>
>>> Can someone help me determine what is wrong?
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Making-an-HTTP-POST-in-Groovy-From-Grails-%28Groovy-Recipies%29-tp26332381p26332381.html
>>> Sent from the grails - user mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>>    http://xircles.codehaus.org/manage_email
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Making-an-HTTP-POST-in-Groovy-From-Grails-%28Groovy-Recipies%29-tp26332381p26332598.html
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Loading...