title: How do I get a JSON response after put/post from MVC
body: <p>I have a jquery routine that calls an MVC action which will do a PUT/POST to an API url. The call from jQuery is fine and works as well as the call to the API using C#. A response is received from the API in JSON format when checked via Firebug/Fiddler.</p>
  
  <p>How do i get that response to be sent back to the calling jQuery?</p>
  
  <p>My C# code is:</p>
  
  <pre><code> public string callAPIPut(string ApiUrl, string JsonString)
      {
          WebRequest request = WebRequest.Create(ApiUrl);
  
          ASCIIEncoding encoding = new ASCIIEncoding();
          byte[] data = encoding.GetBytes(JsonString);
  
          request.ContentType = "application/json; charset=utf-8";
          request.Method = WebRequestMethods.Http.Put;
          request.ContentLength = JsonString.Length;
  
          Stream newStream = request.GetRequestStream();
          newStream.Write(data, 0, JsonString.Length);
          newStream.Close();
  
          return ""; // How do I return the JSON response from the API?
      }
  </code></pre>
  
  <p>When doing a GET i could use something like the following to get the response back to the calling jQuery: </p>
  
  <pre><code>response = (HttpWebResponse)request.GetResponse();
  using (StreamReader sr = new StreamReader(response.GetResponseStream()))
  {
     serviceResponse = sr.ReadToEnd();
  }
  return serviceResponse;
  </code></pre>
  
  <p>I dont know how to return the response when doing a Put/Post?</p>