0

I have the following code in groovy:

def http = new HTTPBuilder( 'http://localhost:8080' )
http.post( path: '/this/is/my/path/'+variable) { resp ->
   println "POST Success: ${resp.statusLine}"
   assert resp.statusLine.statusCode == 200
}

I only want to execute that request. I have a method in another application that when there is a request in that url, I see a result. Problem is that I see nothing.

What might be the problem?

Opal
  • 81,889
  • 28
  • 189
  • 210
Pablo Glez
  • 306
  • 1
  • 7
  • 20

2 Answers2

0

Most likely, your application only responds to GET request and not to POST requests. Try GET instead:

def http = new HTTPBuilder( 'http://localhost:8080' )
http.get( path: '/this/is/my/path/'+variable) { resp ->
    println "GET Success: ${resp.statusLine}"
    assert resp.statusLine.statusCode == 200
}

Also, are you sure that you expect a HTTP status 201 (Created) at this URL?

Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156
0

Could try just opening a simple HttpURLConnection like this:

URL url = new URL("http://localhost:8080/this/is/my/path/${variable}")
HttpURLConnection connection = url.openConnection()
println "responseCode: ${connection.responseCode}" 
assert connection.responseCode == 200
Durandal
  • 5,575
  • 5
  • 35
  • 49