# HTTP POST xml request with headers and authentification

**URL:** <https://discourse.julialang.org/t/http-post-xml-request-with-headers-and-authentification/61026>\
**Category:** General Usage\
**Tags:** http\
**Created:** [May 12, 2021, 2:58pm UTC](https://discourse.julialang.org/t/http-post-xml-request-with-headers-and-authentification/61026 "2021-05-12T14:58:51Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [May 12, 2021, 3:52pm UTC](https://discourse.julialang.org/t/http-post-xml-request-with-headers-and-authentification/61026/2 "2021-05-12T15:52:17Z")

</div>

You can compare the requests using `netcat`, e.g.

```sh
$ netcat -lp 8080

```

and send the requests to `http://localhost:8080`. That should give you an idea what the difference is.

* * *

> [@gitboy16](#):
>
> ```julia
> HTTP.post("https://mywebsite.net/view", 
> [["Content-Type" => "application/xml"],["userpwd" = > "myname:mypassword"]],xml_payload, proxy="", retries=1,verbose=1)
> 
> ```

This looks wrong though, the headers in the second argument should be an array of pairs, i.e.

```julia
["Content-Type" => "application/xml", "userpwd" => "myname:mypassword"]

```

However, do you really want to set a header called `userpwd` to that string? I would guess this uses HTTP basic authentication and you should instead include it in the URL,

```julia
HTTP.post("https://myname:mypassword@mywebsite.net", ...)

```

which HTTP.jl will rewrite to an `Authorization` header after encoding it, e.g.

```julia
HTTP.get("http://user:pass@localhost:8080")

```

gives

```julia
$ netcat -lp 8080
GET / HTTP/1.1
Authorization: Basic dXNlcjpwYXNz
Host: localhost:8080
Accept: */*
User-Agent: HTTP.jl/1.6.1
Content-Length: 0

```

Alternatively you can set the header yourself, e.g.

```julia
using HTTP, Base64
HTTP.get("http://localhost:8080", ["Authorization" => "Basic $(base64encode("user:pass"))")

```

---

_[View the full topic](https://discourse.julialang.org/t/http-post-xml-request-with-headers-and-authentification/61026)._
