1

I'm trying to add a line to my functions.php that does a behind-the-scenes HTTP request submitting some user information to a mailing list URL I have. I'm trying to test the code at the moment, but nothing seems to be working.

I have tried the following:

$url = 'blabla.org/mailinglist/add?' . $user_email;
$request = new WP_Http;
$result = $request->request($url);

and

wp_remote_post($url);

Neither have worked. However, if I Just copy and paste the URL into my web browser, it works fine. Please help!

Thanks,

Tre

  • What exactly are you trying to send/request? Do you need to do anything with the response? When do you want the request fired off? How do you know it's not working? – EAMann Feb 9 '12 at 21:40
  • I just want to post information to the URL. I don't want to get the contents or anything like that. But I want it to happen behind the scenes, so the person isn't redirected or anything like that. – tr3online Feb 10 '12 at 11:14
2

Only use wp_remote_post() if you are actually posting something.

Try using wp_remote_get() with a full url

$url = 'http://blabla.org/mailinglist/add?' . $user_email;
$results = wp_remote_get( $url );
// var_dump( $results );
  • Make sure to check for OK and 200 status with wp_remote_get_response_code() and wp_remote_get_response_message(). This might not work with every server (some are crappy set up), but in all other cases it's good manner to check if you actually got a valid result. – kaiser Nov 28 '14 at 11:23
0

perhaps you're just missing http:// ?

i.e.

$url = 'http://blabla.org/mailinglist/add?' . $user_email;

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.