Coder Social home page Coder Social logo

GET requests with body params? about http HOT 3 OPEN

davidmilo avatar davidmilo commented on July 19, 2024
GET requests with body params?

from http.

Comments (3)

tarcieri avatar tarcieri commented on July 19, 2024

The body: should be sent regardless of the HTTP method used:

https://github.com/httprb/http/blob/main/lib/http/client.rb#L176-L190

Can you provide a complete reproduction of the issue?

from http.

davidmilo avatar davidmilo commented on July 19, 2024

This curl returns 200 response with expected data:

curl --location --request GET 'https://amplitude.com/api/2/taxonomy/event-property' \
--header 'Authorization: Basic MzcwNWMyNGVmMWY5OGMxM2Y3OGY4OTNmN2ZiNDQ5NjI6ZTIwNGMxMjA2ZTc2NDhkZDJjMTI5YjMwM2NlMGQ0OWE=' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'event_type=area_view'

I tried this:

HTTP.basic_auth(user: "3705c24ef1f98c13f78f893f7fb44962", pass: "e204c1206e7648dd2c129b303ce0d49a")
    .get("https://amplitude.com/api/2/taxonomy/event_property", form: { event_type: "area_view" })
    .status
# => 404

I tried this:

HTTP.basic_auth(user: "3705c24ef1f98c13f78f893f7fb44962", pass: "e204c1206e7648dd2c129b303ce0d49a")
    .get("https://amplitude.com/api/2/taxonomy/event_property", body: "event_type=area_view")
    .status
# => <html><title>404: Not Found</title><body>404: Not Found</body></html>

I finally managed to get it to work with this:

HTTP.headers("Authorization" => "Basic MzcwNWMyNGVmMWY5OGMxM2Y3OGY4OTNmN2ZiNDQ5NjI6ZTIwNGMxMjA2ZTc2NDhkZDJjMTI5YjMwM2NlMGQ0OWE=")
    .headers("Content-Type" => "application/x-www-form-urlencoded")
    .get("https://amplitude.com/api/2/taxonomy/event-property", form: { event_type: "area_view" }).status
# => 200

Feel free to use credentials used here. I made a test project so there is on hard hitting that url with those credentials. I will remove it after this gets resolved.

from http.

ixti avatar ixti commented on July 19, 2024
HTTP.basic_auth(user: "3705c24ef1f98c13f78f893f7fb44962", pass: "e204c1206e7648dd2c129b303ce0d49a")

Generates same headers as:

HTTP.headers("Authorization" => "Basic MzcwNWMyNGVmMWY5OGMxM2Y3OGY4OTNmN2ZiNDQ5NjI6ZTIwNGMxMjA2ZTc2NDhkZDJjMTI5YjMwM2NlMGQ0OWE=")

Thus, I'm a bit confused with what could be wrong. Can you try verbose logging?

HTTP.use(logging: { logger: Logger.new($stderr) })
    .basic_auth(...)

from http.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.