[wp-hackers] wp_remote_get() fails but wget works?

Kurt Payne kpayne+wordpress+hackers at gmail.com
Wed Feb 6 17:54:08 UTC 2013


I never did get this to work. :-/

This is bouncing you from the spreadsheet to the login page, then back.
 Their login page must be looking for something more than just a cookie.

I did find a few things to help get you further, though.

First, the WordPress HTTP API can handle cookies.  It just doesn't do so by
default.  The code says so:

// Cookies are not handled by the HTTP API currently. Allow for plugin
authors to handle it
// themselves... Although, it is somewhat pointless without some reference.

I have some sample code up that should work (dd32 will correct me otherwise
:-)).  It's PHP 5.3 (beware the closure)
https://gist.github.com/kurtpayne/4724289

If you remove the unlink call, you can inspect the cookie file afterwards
and verify that the proper cookies were set.

Second, google has published an article on using curl to access spreadsheet
data.  It's got some specialized authentication tokens, but it may be
appropriate to your needs:
https://developers.google.com/gdata/articles/using_cURL

Last, this plugin claims do what you're after
http://wordpress.org/extend/plugins/wpgform/

But it comes with this caveat: "Currently, this plugin only supports Google
Forms that are "Published as a web page" and therefore public. Private
Google Forms are not supported."  So it may be a known issue.

I hope this helps!

--Kurt


On Tue, Feb 5, 2013 at 6:49 AM, Mike Walsh <mpwalsh8 at gmail.com> wrote:

> On Mon, Feb 4, 2013 at 7:07 PM, Dion Hulse (dd32) <wordpress at dd32.id.au
> >wrote:
>
> > If I had to guess, I'd say the Cookies are not being respected/applied
> > for the Redirects, which will most likely cause a redirect loop.
> > Hopefully that'll send you down the right rabbit hole..
> >
> >
> > [ ... snipped ... ]
>
> I think you are right based on what I am able to see comparing wget results
> to wp_remote_get() results.
>
> When I run wget, it returns the Google Form content after the 5th redirect.
>
> When I run wp_remote_get(), the first 5 redirects match the wget run
> exactly but instead of returning the form content, I get another redirect
> for something which has already been requested (the service login URL).
>  Saving the cookies from the wget run I have 4 cookies:  PREF, NID, S, GAPS
>  All of the cookies appear in the data I am dumping from WP_Http but never
> at the same time.
>
> I then tried the command line version of cURL and it behaves the same way
> that wp_remote_get() behaves, timing out after 50 retries (the default).
>  However, if I run cURL and feed it the cookies file I saved from wget it
> works!
>
> This is where I am bit out of my depth.  It seems the GAPS cookie is what
> the login service is looking for but it doesn't come through the redirect
> so it gets into a loop.  Should cookies accumulate through a series of
> redirects?  Based on my experiments, I think they should (or at least I
> need them to) and I think that is happening with wget but isn't happening
> with wp_remote_get() but I am not entirely sure.
>
> Is there a recommended tool for examining headers that I could use for both
> wp_remote_get() and wget?
>
> Is there a way to have cookies pass through a series of redirects?
>
> Thanks,
>
> Mike
>
> --
> Mike Walsh - mpwalsh8 at gmail.com
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list