[prev in list] [next in list] [prev in thread] [next in thread] 

List:       groovy-dev
Subject:    Re: [groovy-dev] Post Data to URL
From:       Merlyn Albery-Speyer <curious.attempt.bunny () gmail ! com>
Date:       2011-03-25 13:58:41
Message-ID: 65066BDE-E4B4-4B96-93F2-F037B95C6510 () gmail ! com
[Download RAW message or body]

Hey Kevin,

You might also want to look at  HTTPBuilder if you're making heavy use  
of HTTP. http://groovy.codehaus.org/modules/http-builder/doc/contentTypes.html
With HTTPBuilder you can use uri.query = [ key:value, ... ] which  
would also make the code more readable.

Cheers,
Merlyn

On Mar 25, 2011, at 6:15 AM, Guillaume Laforge wrote:

> Hi Kevin,
> 
> Is it the exact script you're executing?
> Because you forget quotes around your URLs, for a start.
> 
> Could you also show us the errors that you get?
> 
> Guillaume
> 
> On Fri, Mar 25, 2011 at 14:09, kevinmortimer
> <kevin@cordistechnologies.com> wrote:
> > Hi All
> > 
> > Not too familiar with Groovy. I have my code to send data to a url  
> > but i am
> > getting an error on line 5
> > 
> > String data = URLEncoder.encode(client_id, "UTF-8") + "=" +
> > URLEncoder.encode(708210874383.apps.googleusercontent.com, "UTF-8");
> > data += "&" + URLEncoder.encode(client_secret, "UTF-8") + "=" +
> > URLEncoder.encode(cFXNsqPNejIrSrFedcJ8uUAY, "UTF-8");
> > data += "&" + URLEncoder.encode(redirect_uri, "UTF-8") + "=" +
> > URLEncoder.encode(http://www.cordistechnologies.com/homepage.php,  
> > "UTF-8");
> > data += "&" + URLEncoder.encode(grant_type, "UTF-8") + "=" +
> > URLEncoder.encode(authorization_code, "UTF-8");
> > data += "&" + URLEncoder.encode(code, "UTF-8") + "=" +
> > URLEncoder.encode(4/CiHV_OWQUYA0Z-5v4Th8KTlkgoVR, "UTF-8");
> > 
> > URL url = new URL(https://accounts.google.com/o/oauth2/token);
> > URLConnection conn = url.openConnection();
> > conn.setDoOutput(true);
> > OutputStreamWriter wr = new  
> > OutputStreamWriter(conn.getOutputStream());
> > wr.write(data);
> > wr.flush();
> > 
> > String response = conn.getInputStream().getText("utf-8");
> > wr.close();
> > return response;
> > 
> > --
> > View this message in context: \
> > http://groovy.329449.n5.nabble.com/Post-Data-to-URL-tp4264065p4264065.html Sent \
> > from the groovy - dev mailing list archive at Nabble.com. 
> > ---------------------------------------------------------------------
> > To unsubscribe from this list, please visit:
> > 
> > http://xircles.codehaus.org/manage_email
> > 
> > 
> > 
> 
> 
> 
> -- 
> Guillaume Laforge
> Groovy Project Manager
> Head of Groovy Development at SpringSource
> http://www.springsource.com/g2one
> 
> ---------------------------------------------------------------------
> 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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic