You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, the above code is invalid in multiple ways and will not run.
Here is the correct equivalent code:
varclient=new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));//Content-Type header must be specified in this wayvarrequest=new HttpRequestMessage(HttpMethod.Post,"https://myurl.com/endpoint");
request.Headers.Add("accept","application/json, text/plain, */*");
request.Headers.Add("accept-language","en-US,en;q=0.8");
request.Headers.Add("authorization","Bearer MYTOKEN");
request.Headers.Add("origin","https://origin.myurl.com");
request.Headers.Add("referer","https://referer.myurl.com/");
request.Headers.Add("sec-ch-ua","\"Brave\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"");
request.Headers.Add("sec-ch-ua-mobile","?0");
request.Headers.Add("sec-ch-ua-platform","\"Windows\"");
request.Headers.Add("sec-fetch-dest","empty");
request.Headers.Add("sec-fetch-mode","cors");
request.Headers.Add("sec-fetch-site","same-site");
request.Headers.Add("sec-gpc","1");
request.Headers.Add("user-agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36");varcontent=new StringContent("{\"TeamIds\":[57566],\"StartTime\":\"2024-03-01T00:00:00.000Z\",\"EndTime\":\"2024-05-31T23:59:59.999Z\"}", System.Text.Encoding.UTF8,"application/json");//This is the proper way to specify encoding
request.Content =content;varresponse=await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
Screenshots or Videos
No response
Operating System
Windows
Postman Version
11.0.0
Postman Platform
Postman App
User Account Type
Signed Out User
Additional Context?
There are other ways to improve the C# code above (for instance, JsonContent instead of StringContent) but this is the minimal amount of changes to make the code useable
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Describe the Issue
When using "Code snippet" > "C# - HttpClient", the code generated is invalid and will not run.
Steps To Reproduce
Import the following curl request (I used a real request, but changed some values for the sake of privacy):
After importing the above request, generate a code snippet using "Code snippet" > "C# - HttpClient". The following snippet is generated:
However, the above code is invalid in multiple ways and will not run.
Here is the correct equivalent code:
Screenshots or Videos
No response
Operating System
Windows
Postman Version
11.0.0
Postman Platform
Postman App
User Account Type
Signed Out User
Additional Context?
There are other ways to improve the C# code above (for instance,
JsonContent
instead ofStringContent
) but this is the minimal amount of changes to make the code useableThe text was updated successfully, but these errors were encountered: