Laxman Dussa

Laxman Dussa

  • NA
  • 117
  • 4.2k

mvc with webapi

Jun 11 2019 11:47 PM
  1. public static string DoWebreqeust(string url, string json)  
  2. {  
  3. try  
  4. {  
  5. HttpWebRequest request = (HttpWebRequest)  
  6. WebRequest.Create(url); request.KeepAlive = false;  
  7. request.ProtocolVersion = HttpVersion.Version10;  
  8. request.Method = "POST";  
  9. byte[] postBytes = Encoding.UTF8.GetBytes(json);  
  10. request.ContentType = "application/json; charset=UTF-8";  
  11. request.Accept = "application/json";  
  12. // request.ContentType = "application/x-www-form-urlencoded";  
  13. request.ContentLength = postBytes.Length;  
  14. Stream requestStream = request.GetRequestStream();//error line  
  15. requestStream.Write(postBytes, 0, postBytes.Length);  
  16. requestStream.Close();  
  17. HttpWebResponse response = (HttpWebResponse)request.GetResponse();  
  18. string result;  
  19. using (StreamReader rdr = new StreamReader(response.GetResponseStream()))  
  20. {  
  21. result = rdr.ReadToEnd();  
  22. }  
  23. return result;  
  24. }  
  25. catch (Exception ex)  
  26. {  
  27. return "";  
  28. }  
  29. }  
above code 
 
i send a 3 pdf files with base64 data to api
 
'responseStream.Length' threw an exception of type 'System.NotSupportedException'.
Length = 'dataStream.Length' threw an exception of type 'System.NotSupportedException'
Position = 'dataStream.Position' threw an exception of type 'System.NotSupportedException' 

Answers (5)