3

Is there any way to construct post data and send it to an external URL, like how a form will send POST data to action URL?

I am aware of drupal_goto() function, but it is not possible to send POST data using it. I am also aware of drupal_http_request(), but I do not want a response from the URL here. I just want to submit data to the URL from my custom module. How can I achieve this? Any help is appreciated.

  • Why can't you just use drupal_http_request and ignore the response if you don't need it? Also, shouldn't you be checking that your connection has been made successfully? What if there was an error? – Clive Jan 27 '12 at 14:41
  • If I use drupal_http_request(), the request will be processed and I will get a response within the same function. But I want the user be redirected to the external page to which I am sending POST data. So how do I pass the data and also redirect the user to the same page? – Vivek Jan 27 '12 at 14:47
  • 1
    You can't do that with PHP, see stackoverflow.com/questions/3045097/… – Clive Jan 27 '12 at 14:50
  • thanks for the reference. So can I construct a new form with required values and trigger its action programatically to achieve this? – Vivek Jan 27 '12 at 14:52
  • Yeah that's the way I'd do it, forward the user on to a page which builds up the form (with the correct action attribute) with the fields already in it (probably using hidden inputs) and use javascript to submit the form as soon as the document is ready :) – Clive Jan 27 '12 at 14:54
1

This is a PHP question, really. But here's an answer: http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl/

Many many caveats; read the comments.

0

CURL is th swiss army knife to do such things. CURL stands for client URL library. It allows you to do everything programmatically what you can do manually in a browser (and a lot more).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.