Quantcast
Channel: Questions in topic: "httpwebrequest"
Viewing all articles
Browse latest Browse all 190

Http post request - dictionary as value

$
0
0
I'm trying to do a POST request using http in Unity, based on curl request. That's my current piece of code: var identifiers = new Dictionary { {"os", "Windows 10"} }; string s = string.Join(";", identifiers.Select(x => x.Key + "=" + x.Value).ToArray()); var values = new Dictionary { {"user_id", "testId"}, {"type", "test"}, {"identifiers", s} }; client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("MY_ID"); var content = new FormUrlEncodedContent(values); var response = await client.PostAsync("_server_", content); var responseString = await response.Content.ReadAsStringAsync(); The problem is, the server responds with information > *{"extra":{"identifiers":["must be of dict type"]},"message":"Input failed validation","status_code":422,"type":"ValidationException"}* What I think is the problem is the fact, that the whole dictionary is put inside of a string and it is treated as such. Is there any way to overcome this? Here is the curl code I want to pass to server: curl - X POST \ https://myserver.com -H 'Authorization: myID' \ -H 'Content-Type: application/json' \ -H 'X-Api-Version: 1.1.0' \ -d '{ "user_id": "testid", "type": "testType", "identifiers": { "field01": "value01", "field02": "value02" } }'

Viewing all articles
Browse latest Browse all 190

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>