0

I HAVE EDITED THE QUESTION TO SIMPLIFY IT

I have an app working in a domain like this:

http://localhost:8092/myapp

If I access to

http://localhost:8092/myapp/ticket/save

with a browser, everything goes fine. However, if I make a CURL call from command line to another controller, and from there I try to redirect to the controller "ticket" method "save", as shown in the URL above, it works only if the call is made from localhost. But if I made the call from a remote server it won't do anything.

This is the curl call:

curl --location http://192.168.1.18:8092/myapp/trans/index

and the index method:

def index() {
    print "index"

    redirect(controller: "ticket", action:"save")
}

When making the call from a remote client, Grails won't do the redirection and it does not show any error. However, in the terminal, it says:

curl  --location  http://192.168.1.18:8092/Post-editor_Grails/traduccion/index
curl: (7) couldn't connect to host

BUT the call does reach the server, as "index" gets printed in Grails console. So I asume that error comes from the redirection.

I have tried to set absolute:true in the redirect, as shown here:

Grails redirect with reverse proxy

but it does not work either.

Any ideas?

Marcos Fernandez
  • 556
  • 9
  • 22
  • If that's your actual code you forgot to wrap the URL in quotes – apokryfos Dec 04 '17 at 09:30
  • @apokryfos, solved. In the actual code it is a variable previously defined – Marcos Fernandez Dec 04 '17 at 09:56
  • I'm also assuming you've tried with the `CURLOPT_POST => count($arrayContent)` commented out (in addition to the `CURLOPT_POSTFIELDS`). Also `CURLOPT_CUSTOMREQUEST => "POST"` is not needed when you have the other 2 options – apokryfos Dec 04 '17 at 10:08
  • Hold on, your commandline curl request is indicates that you want to send JSON but your PHP curl request is sending a form encoded string. Try the solution at https://stackoverflow.com/questions/11079135/how-to-post-json-data-with-php-curl – apokryfos Dec 04 '17 at 10:11
  • @apokryfos, thanks, but POST is not the problem. I have modified the question as I have found that the problem comes when I make the CURL request from a remote client. It works fine if I make the request from the same machine Grails is running on. – Marcos Fernandez Dec 04 '17 at 12:13

1 Answers1

0

Nah, forget this question. In Config.groovy I had:

grails.serverURL = "http://localhost:8092/${appName}"

Just need to change localhost to 192.168.... (it needs the "absolute:true" though)

I don't know if I should delete the question

Marcos Fernandez
  • 556
  • 9
  • 22