9

If I try to access the following from firefox everything works even if I'm not logged in

http://api.stackexchange.com/2.0/users/19068?order=desc&sort=reputation&site=stackoverflow

However

wget http://api.stackexchange.com/2.0/users/19068?order=desc&sort=reputation&site=stackoverflow

gives

Resolving api.stackexchange.com... 64.34.119.12
Connecting to api.stackexchange.com|64.34.119.12|:80... connected.
HTTP request sent, awaiting response... 400 Bad Request
2012-05-08 01:46:49 ERROR 400: Bad Requ

Why do I get an error message?

0

2 Answers 2

15

You'll need to quote that URL.

wget 'http://api.stackexchange.com/2.0...&site=stackoverflow'
     ^                                                      ^

(And note that the payload is gzip-compressed.)

1
  • 4
    For technical reference, this happens because the & in the URL signifies to the shell to start a new background process and run the code following that.
    – dunsmoreb
    Commented May 7, 2012 at 22:00
6

The problem is the & characters in the URL. In most shells, foo & bar means "start running foo in the background while running bar in the foreground". Put quotes around the URL to make sure it gets passed as a single parameter to wget.

You must log in to answer this question.