The way I do it and is working is:
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://url"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{\"user\":\"test\"," + "\"password\":\"bla\"}"; streamWriter.Write(json); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); }
I wrote a library to perform this task in a simpler way, it is here: https://github.com/ademargomes/JsonRequest
Hope it helps.
Related Posts:
- How to make an HTTP POST web request
- C# HttpClient An existing connection was forcibly closed by the remote host
- How can I parse JSON with C#?
- How to convert JSON to XML or XML to JSON?
- The request was aborted: Could not create SSL/TLS secure channel
- System.Net.Http: missing from namespace? (using .net 4.5)
- The request was aborted: Could not create SSL/TLS secure channel
- The request was aborted: Could not create SSL/TLS secure channel
- Deserialize JSON with C#
- HttpWebRequest-The remote server returned an error: (400) Bad Request
- Convert JSON String To C# Object
- Read and parse a Json File in C#
- Parse Json string in C#
- The server committed a protocol violation. Section=ResponseStatusLine ERROR
- JSON.NET Error Self referencing loop detected for type
- Unexpected character encountered while parsing value
- How to post data to specific URL using WebClient in C#
- How to properly make a http web GET request
- Convert JSON String to JSON Object c#
- What is IP address ‘::1’?
- What is the yield keyword used for in C#?
- Join/Where with LINQ and Lambda
- C# compiler error: “not all code paths return a value”
- How to use SQLite in Visual Studio 2017?
- C# equivalent of C++ map
- The page was not displayed because the request entity is too large on IIS
- Export Pervasive to MySQL (C#)
- Why use the params keyword?
- What does plus equals(+=) operator means here?
- finding the maximum length of lists in c#
- foreach vs someList.ForEach(){}
- The located assembly’s manifest definition does not match the assembly reference
- LEFT OUTER JOIN in LINQ
- OnTriggerEnter not working at Unity3D
- The requested resource does not support HTTP method ‘GET’
- How can I find a specific element in a List
? - Rename a file in C#
- What does mscorlib stand for?
- What is the best way to iterate over a dictionary?
- What is and how to fix System.TypeInitializationException error?
- How to move 2D Object with WASD in Unity
- The Object you want to instantiate is null. Unity 3D
- Convert date yyyyMMdd to system.datetime format
- How to bind a model to a kendo Combobox in order to use the models validatation?
- MSHTML DLL on Windows 10
- Adding values to a C# array
- What does {0} mean when found in a string in C#?
- How to use html.ValidationMessageFor
- EF 5 Enable-Migrations : No context type was found in the assembly
- What does the @ symbol before a variable name mean in C#?
- What is the C# version of VB.net’s InputDialog?
- Visual studio 2019 freezes when debugging
- How to add comments into a Xaml file in WPF?
- Are 2 dimensional Lists possible in c#?
- Passing just a type as a parameter in C#
- How to stop C# console applications from closing automatically? [duplicate]
- Can I send SMS Messages from a C# Application?
- How do you sort a dictionary by value?
- EntityType has no key defined error
- How do I restart my C# WinForm Application?
- WSACancelBlockingCall exception
- Padding is invalid and cannot be removed?
- Why is it that “No HTTP resource was found that matches the request URI” here?
- Best way to reverse a string
- C# Foreach statement does not contain public definition for GetEnumerator
- How do I exit a foreach loop in C#?
- Fastest way to remove first char in a String
- How to convert datetime format to date format in crystal report using C#?
- c# identifier expected?
- Root element is missing
- Unable to copy file – access to the path is denied
- Most efficient way to remove special characters from string
- When do we use ANTLR
- How would you count occurrences of a string (actually a char) within a string?
- Rotate object in Unity 3D
- C# equivalent to Java’s charAt()?
- How do I concatenate two arrays in C#?
- How to play a sound in C#, .NET
- Why am I getting ‘Assembly ‘*.dll’ must be strong signed in order to be marked as a prerequisite.’?
- Convert SQL to LINQ Query
- Which passwordchar shows a black dot (•) in a winforms textbox?
- Draw Rectangle in XNA using SpriteBatch
- How do I fix a .NET windows application crashing at startup with Exception code: 0xE0434352?
- How to resolve file being used by another process?
- How to crop an image using C#?
- c# .net change label text
- Check if a string is a palindrome
- How do you wait for input on the same Console.WriteLine() line?
- Why doesn’t C# have header files? Will the namespace take care of everything?
- How to avoid a System.Runtime.InteropServices.COMException?
- Define: What is a HashSet?
- Convert string to decimal, keeping fractions
- Format of the initialization string does not conform to specification starting at index 0
- How can I generate random alphanumeric strings?
- How do you do a deep copy of an object in .NET?
- How to get POSTed JSON in Flask?
- Get local IP address
- Delay function in C#
- Cannot declare instance members in a static class in C#
- How to convert HTML to PDF using iTextSharp