Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3619

Python equivalent of HttpClient PostAsync for sending an array of parameters as part of an API get request

$
0
0

I have been unable to find how to pass/post parameters for an enterprise API.

This is the example from documenation in C#:

string json = string.Empty;using ( HttpClient client = new HttpClient() ){   string object= "UserNames";   string method = "methodname";   string requestUrl = $"http://server/service/object/invoke/{object}?method={method}";   // provide token in the Authorization header   client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization","b/authorizationkey" );   string[] parameters = new[] { "sa", "", "", "", "" };   // pass the array of parameters as the request data   string contentStr = JsonConvert.SerializeObject( parameters );   // send the post request   HttpResponseMessage response = client.PostAsync( requestUrl.ToString(), new StringContent( contentStr, Encoding.UTF8, "application/json" ) ).Result;   using ( HttpContent content = response.Content )   {      Task<string> result = content.ReadAsStringAsync();      json = result.Result;   }}

I've been using 'requests' package successfully for getting information from the api but am at a roadblock when trying to find an equivalent way to PostAsync.

Also, I know this isn't a great post, but I need to start a post somewhere to start to be able to upvote or downvote things here.


Viewing all articles
Browse latest Browse all 3619

Trending Articles



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