I'm trying to send a unitywebrequest
var webRequest = UnityWebRequest.Post("https://example.com/api/auth/login","{\"username\": \"demo2\",\"password\": \"demo2\",\"password2\": \"demo2\"}");
webRequest.SetRequestHeader("accept", "application/json");
webRequest.SetRequestHeader("Content-Type", "application/json");
webRequest.certificateHandler = new ForceAcceptAllCertificates();
var operation = webRequest.SendWebRequest();
while (!operation.isDone)
await UniTask.Yield();
responseCode = (HttpStatus)webRequest.responseCode;
webRequest.certificateHandler.Dispose();
webRequest.uploadHandler?.Dispose();
always I keep getting 400 error. What i'am do wrong
curl -X 'POST'
'https://example.com/api/auth/login'
-H 'accept: application/json'
-H 'Content-Type: application/json'
-d '{
"username": "demo",
"password": "demo",
"isLDAP": false
}'
Besides the fact that your two JSON are quite different ;)
From
UnityWebRequest.Post
withstring, string
parametersYou might rather want to use raw bytes and construct the request from scratch like e.g.