Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8143483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:08:06+00:00 2026-06-06T13:08:06+00:00

I am working with an API and trying to do a JSON PUT request

  • 0

I am working with an API and trying to do a JSON PUT request within C#. This is the code I am using:

    public static bool SendAnSMSMessage()
    {
        var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://apiURL");
        httpWebRequest.ContentType = "text/json";
        httpWebRequest.Method = "PUT";

        using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
        {
            string json = **// Need to put data here to pass to the API.**

            streamWriter.Write(json);
        }
        var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            var responseText = streamReader.ReadToEnd();
            //Now you have your response.
            //or false depending on information in the response
            return true;
        }
    }

The problem is I can’t figure out how to pass the data to the API. So like in JavaScript I would do something like this to pass the data:

        type: 'PUT',
        data: { 'reg_FirstName': 'Bob',
                'reg_LastName': 'The Guy',
                'reg_Phone': '123-342-1211',
                'reg_Email': 'someemail@emai.com',
                'reg_Company': 'None',
                'reg_Address1': 'Some place Dr',
                'reg_Address2': '',
                'reg_City': 'Mars',
                'reg_State': 'GA',
                'reg_Zip': '12121',
                'reg_Country': 'United States'

How would I go about doing the same in C#? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:08:07+00:00Added an answer on June 6, 2026 at 1:08 pm
    httpWebRequest.ContentType = "text/json";
    

    should definitely be:

    httpWebRequest.ContentType = "application/json";
    

    Other than that I don’t see anything wrong with your current code.

    As far as the JSON generation part is concerned you could use a JSON serializer:

    var serializer = new JavaScriptSerializer();
    
    string json = serializer.Serialize(new 
    {
        reg_FirstName = "Bob",
        reg_LastName = "The Guy",
        ... and so on of course
    });
    

    In this example I have obviously used an anonymous object but you could perfectly fine define a model whose properties match and then pass an instance of this model to the Serialize method. You might also want to checkout the Json.NET library which is a third party JSON serializer which is lighter and faster than the built-in .NET.


    But all being said, you might also have heard of the ASP.NET Web API as well as the upcoming .NET 4.5. If you did, you should be aware that there will be an API HTTP web client (HttpClient) which is specifically tailored for those needs. Using a WebRequest to consume a JSON enabled API will be considered as obsolete code in a couple of months. I am mentioning this because you could use the NuGet to use this new client right now and simplify the life of the poor soul (tasked to migrate your code to .NET X.X) that will look at your code a couple of years from now and probably wouldn’t even know what a WebRequest is 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with an API ( DocumentCloud ) using jQuery/JSON. I'm trying to retrieve
I just started working using Google Maps API yesterday, and trying to set up
I have this code, but can't get it all working. I am trying to
I'm working with the Wufoo api ( https://{subdomain}.wufoo.com/api/v3/forms/{formIdentifier}/entries.{xml|json} ) trying to get all of
I'm working on an Android project using API 7 and I'm trying to start
i am trying to write a API using JSP/JSTL to generate JSON output but
I am trying to send a json object using GET method. My code: $.ajax({
I am working with the MusicPlayer API and I am trying to solve a
`I am working with an API that sends back an XML response upon request.
I've been trying to work with the Google Calendar JSON API, but have been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.