3

This code produces a POST request:

urllib2.urlopen("http://somedomain.com/", data)

I would like to produce a GET request - any ideas on how to do that?

Thanks for the help!

2 Answers 2

5

Try:

urllib2.urlopen("http://somedomain.com/?" + data)

[edited]

If you want to send xml/json/etc data in the body, use something like:

urllib2.urlopen("http://somedomain.com/?" + parameters, data)

This will use the POST method, but any "GET" parameters will also be available to your application.

Sign up to request clarification or add additional context in comments.

2 Comments

What if I need to include a body in my request?
I don't think you are supposed to include a body when using the GET method. See stackoverflow.com/questions/978061/http-get-with-request-body
0

Alternatively, you also use requests that has a more explicit API:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.