Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

RE: [groovy-user] HTTP Post/Get

Anders Viklund

2010-03-11

Replies: Find Java Web Hosting

Author LoginPost Reply
hmm, there are still some problems, its not closing the connection to the client for some reason. Client is just hanging.

how can I fix this problem?

Thanks!

 server = new ServerSocket(8104)
 while(true) {
     server.accept() { socket ->
        
         socket.withStreams { input, output ->
           
             def s = new Socket("localhost", 9090)
           
             s.withStreams{ ois, oos ->
                oos << input
                output << ois
             }
         }
     }
 }


From: viklund_anders@hotmail.com
To: user@groovy.codehaus.org
Date: Thu, 11 Mar 2010 23:13:30 +0000
Subject: RE: [groovy-user] HTTP Post/Get

This is now working, but how can I print the input/output streams or transform them into strings?

 server = new ServerSocket(8890)
 while(true) {
     server.accept() { socket ->
        
         socket.withStreams { input, output ->
           
         def s = new Socket("localhost", 9090)
         def result
       
         s.withStreams{ ois, oos ->
            oos << args
            output << ois
         }
         s.close()
         }
     }
 }


From: viklund_anders@hotmail.com
To: user@groovy.codehaus.org
Date: Thu, 11 Mar 2010 20:52:50 +0000
Subject: RE: [groovy-user] HTTP Post/Get

And if I would like to create a http proxy, just like tcpmon , how to forward the request if the server looks something like this?

I would like to grab the input/output, but its just returning an integer instead of a string as it supposed to do.

 server = new ServerSocket(5000)
 while(true) {
     server.accept() { socket ->
         socket.withStreams { input, output ->

         def s = new Socket("localhost", 8080)
         s.withStreams{ ois, oos ->
            oos << args
            result = ois.read()
         }
         s.close()

             output.withWriter { writer ->
                 writer << result
             }
         }
     }
 }


From: tim.yates@gmail.com
Date: Thu, 11 Mar 2010 20:12:32 +0000
To: user@groovy.codehaus.org
Subject: Re: [groovy-user] HTTP Post/Get

Posting the form on http://www.snee.com/xml/crud/posttest.html with the http-builder package would look something like this:

@Grab( 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.0-RC2' )
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.URLENC

def http = new HTTPBuilder( 'http://www.snee.com/xml/crud/' )
http.post( path:'posttest.cgi',
           body:[ fname:'Tim' , lname:'Yates' ],
           requestContentType:URLENC ) { resp, reader ->
  println "Response status: ${resp.statusLine}"
  System.out << reader
}

That posts the 2 fields on that page, then prints the results

Not used http-builder before though, so there may be a neater way of doing it :-)

Tim


On Thu, Mar 11, 2010 at 5:24 PM, Anders Viklund <viklund_anders@hotmail.com> wrote:
wow!

How to post any contents to the page before read it?


From: tim.yates@gmail.com
Date: Thu, 11 Mar 2010 16:05:25 +0000
To: user@groovy.codehaus.org
Subject: Re: [groovy-user] HTTP Post/Get


new URL( "http://www.google.com" ).text

On Thu, Mar 11, 2010 at 4:02 PM, Anders Viklund <viklund_anders@hotmail.com> wrote:
Hi,

is there a simple way to fetch the contents of a web page using Groovy?

Thanks!


Hotmail: Trusted email with Microsoft’s powerful SPAM protection. Sign up now.



Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. Sign up now.



Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. Sign up now.

Hotmail: Trusted email with powerful SPAM protection. Sign up now.

Hotmail: Trusted email with Microsoft’s powerful SPAM protection. Sign up now.
©2008 gg3721.com - Jax Systems, LLC, U.S.A.