# Difficulty with cookies and setting login information

**URL:** <https://discourse.julialang.org/t/difficulty-with-cookies-and-setting-login-information/42804>\
**Category:** General Usage\
**Tags:** question, http\
**Created:** [July 9, 2020, 9:14pm UTC](https://discourse.julialang.org/t/difficulty-with-cookies-and-setting-login-information/42804 "2020-07-09T21:14:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mantzaris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mantzaris/32/3852_2.png) [@mantzaris](https://discourse.julialang.org/u/mantzaris)\
**Post date:** [July 9, 2020, 9:14pm UTC](https://discourse.julialang.org/t/difficulty-with-cookies-and-setting-login-information/42804/1 "2020-07-09T21:14:51Z")

</div>

I am having difficulty using HTTP.jl to login to a page by passing the username and the password. This is the site’s HTML for the login form:

```julia
<form id="login_form" name="login_form" class="form-horizontal" method="post" novalidate action="https://site.com/login/try/id/normal">
   <div class="login_align">
   <fieldset id="inputs">
   <input id="email" name="email" type="text" placeholder="Email" autofocus required>
   <label for="email"></label>
   <input id="password" name="password" type="password" placeholder="Password" required>
   <label for="password"></label>
   </fieldset>
   <fieldset id="actions">
   <input type="submit" id="submit" value="Log in">

```

I used the command:

```julia
res = HTTP.request("POST", "https://site.com/login/try/id/normal", 
       Dict("email"=>"user@mail.com","password"=>"enter123"))

```

and get the response that all looks like the request passed

```julia
HTTP.Messages.Response:
---
HTTP/1.1 200 OK
Date: Thu, 09 Jul 2020 04:0:0 GMT
Server: Apache/1.3.2 (Ubuntu)
X-Powered-By: PHP/6.0Ubuntu14.11
Set-Cookie: session_name=123987; path=/; HttpOnly
...

```

but subsequent calls all lead me to believe that it did not work, or that I am not using the state change saved. Subsequent calls produce the same as response as before without key login fields changing. Am I doing something wrong? Maybe the dictionary with the login details needs modification?  
(I even tried to use a JSON instead via):

```julia
s = "{\"email\" : \"user@mail.com\", \"password\" : \"enter123\"}"
jj=JSON.parse(s)
res = HTTP.request("POST", "https://site.com/login/try/id/normal", jj )

```

and the results do not indicate successful login

I tried just having `cookies=true`, So if cookies=Dict(name=\>value) , should be set manually in subsequent requests, should  
`res_location_search = HTTP.request("GET", "https://website.com")`  
become:  
`res_location_search = HTTP.request("GET", "https://website.com",cookies=Dict(name=>value))`  
if so, I got a response:

```julia
HTTP.Messages.Request:
"""
POST /login/try/id/normal HTTP/1.1
password: enter123
email: user@mail.com
Cookie: session_name=kog123321
Host: site.com
User-Agent: HTTP.jl/1.2.0
Content-Length: 0

```

then should the cookie be sent as  
`cookies=Dict("session_name"=>"kog123321")`  
so that the request becomes?:  
`res_location_search = HTTP.request("GET","https://website.com",cookies=Dict("session_name"=>"kog123321"))`

I tried this but still it does not change the state to logged in

* * *

it works with `PyCall` via:

```julia
py"""
import requests
ck = {'email': $(USER_NAME), 'password': $(PASSWORD)}
s = requests.Session()
r = s.post($(POST_LOGIN_URL), data=ck)
r2 = s.get($(MEMBER_URL))
r3 = r2.content

"""

```
