# Help translating curl command to HTTP.jl

**URL:** <https://discourse.julialang.org/t/help-translating-curl-command-to-http-jl/53790>\
**Category:** New to Julia\
**Tags:** question, package\
**Created:** [January 22, 2021, 5:08pm UTC](https://discourse.julialang.org/t/help-translating-curl-command-to-http-jl/53790 "2021-01-22T17:08:39Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [January 25, 2021, 4:28pm UTC](https://discourse.julialang.org/t/help-translating-curl-command-to-http-jl/53790/21 "2021-01-25T16:28:32Z")

</div>

The basic change you’ve made seems to be the addition of Accept and Content-Type headers. Why did the curl and python apparent equivalents to your original work? Do curl and python automatically add those extra headers you’ve added, or perhaps does HTTP.jl include bad values for those headers by default?

---

<div class="post-metadata">

**Author:** ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Post date:** [January 25, 2021, 4:40pm UTC](https://discourse.julialang.org/t/help-translating-curl-command-to-http-jl/53790/22 "2021-01-25T16:40:41Z")

</div>

It seems the default parameters are different. For Python’s `requests` library:

```julia
req = pyimport("requests")
req.post("http://localhost:8080", 
Dict("grant_type" => "client_credentials"), 
headers = Dict("Authorization" => "Basic $refreshtoken"))

```

```julia
~ > nc -l 8080
POST / HTTP/1.1
Host: localhost:8080
User-Agent: python-requests/2.22.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Authorization: Basic OT...E=
Content-Length: 29
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials

```

for curl:

```julia
run(`curl -X "POST" -H "Authorization: Basic $refreshtoken" -d grant_type=client_credentials http://localhost:8080`)

```

```julia
~ > nc -l 8080
POST / HTTP/1.1
Host: localhost:8080
User-Agent: curl/7.68.0
Accept: */*
Authorization: Basic OT...E=
Content-Length: 29
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials

```

And HTTP.jl

```julia
HTTP.post("http://localhost:8080", ["Authorization" => "Basic $refreshtoken"], "grant_type=client_credentials")

```

```julia
~ > nc -l 8080
POST / HTTP/1.1
Authorization: Basic OT...E=
Host: localhost
User-Agent: HTTP.jl/1.5.3
Content-Length: 29

grant_type=client_credentials

```

Whether this is good or bad I cannot judge. For my usecase it was bad since it deviates from what you have to do in curl which seems to be the standard in all the API docs. But with the `nc -l 8080` trick this was quite easy to figure out.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [January 25, 2021, 4:40pm UTC](https://discourse.julialang.org/t/help-translating-curl-command-to-http-jl/53790/23 "2021-01-25T16:40:42Z")

</div>

See [https://github.com/JuliaWeb/HTTP.jl/issues/661](https://github.com/JuliaWeb/HTTP.jl/issues/661)

---

<div class="post-metadata">

**Author:** ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Post date:** [January 25, 2021, 4:48pm UTC](https://discourse.julialang.org/t/help-translating-curl-command-to-http-jl/53790/24 "2021-01-25T16:48:24Z")

</div>

I also need to set

```julia
    "Content-Type" => "application/x-www-form-urlencoded"

```

which is also the default in both requests and curl

Should I open a separate issue?

---

<div class="post-metadata">

**Author:** ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Post date:** [January 25, 2021, 5:11pm UTC](https://discourse.julialang.org/t/help-translating-curl-command-to-http-jl/53790/25 "2021-01-25T17:11:04Z")

</div>

Based on @mbauman’s initial comment on the issue I did the request without `"Accept" => "*/*"` and it still worked so in this case the problem really seems to be `"Content-Type"=>"application/x-www-form-urlencoded"`.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [January 25, 2021, 5:32pm UTC](https://discourse.julialang.org/t/help-translating-curl-command-to-http-jl/53790/26 "2021-01-25T17:32:18Z")

</div>

It’s interesting because that `Content-Type` doesn’t appear in Requests’ [default headers](https://github.com/psf/requests/blob/c2b307dbefe21177af03f9feb37181a89a799fcc/requests/utils.py#L817-L826). Do they dynamically add it in certain situations? Ah, it looks like it does indeed depend upon the body — it’ll either be a `multipart` or this `x-www-form-urlencoded` or nothing:

[requests/models.py#L505-L520](https://github.com/psf/requests/blob/4f6c0187150af09d085c03096504934eb91c7a9e/requests/models.py#L505-L520) (Apache License 2.0)

[Previous page](https://discourse.julialang.org/t/help-translating-curl-command-to-http-jl/53790.md?page=1)
