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

2
  • 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
    Commented Feb 9, 2012 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
    Commented Feb 10, 2012 at 11:14

2 Answers 2

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 );
1
  • 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
    Commented Nov 28, 2014 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 and acknowledge you have read our privacy policy.

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