Reputation:
I want to perform a request with the certain headers, cookies and form values. Here is how I'm doing that:
import Network.HTTP.Conduit
import Network.HTTP.Types
--.......omitted
configReq r = r { method = methodPost
, requestHeaders = (requestHeaders r) ++ [
(DS.fromString "Referer", DS.fromString "https://server...."),
(DS.fromString "SomeHeader2", DS.fromString "fdsfdsfds")
]
, requestBody = RequestBodyLBS (Aeson.encode $ Map.fromList [("email", "[email protected]"), ("password", "7890")])
, secure = True
, cookieJar = [myCookie]
}
This seems like it should work. But it doesn't because a server returns 400
--> "X-Response-Body-Start","Invalid input."
no matter what the email and the password are. Note that this is not a request which perform something per se, it is an authentication request (the same one you send when you click "login" button) that's why it has email
and password
form values (the same as on its /login
page).
I figure that even so the form values email
and password
are in the request, they have to be set differently, meaning they have to be not in requestBody
but in some different place.
So for now the question is where do I have to put email
and password
if not in requestBody
?
Upvotes: 0
Views: 483
Reputation: 31305
Most likely, the web server is expected URL encoded form data, not a JSON request body. You can use the aptly-named urlEncodedBody function for that purpose.
Upvotes: 2