Gopi Krishnan

Gopi Krishnan

  • NA
  • 308
  • 7.7k

Web API Consuming

Oct 21 2019 5:06 AM
Error "Cannot send a content-body with this verb-type."
 
When i call API to invoke GET Method with json parmater using Httpwebrequest class,i got the above error.kindly share any solution.
  1. url = "xxxxx";  
  2. Uri myUri = new Uri(url);  
  3. strUserName = "test";  
  4. strPassword = "*******";  
  5. WebRequest myWebRequest = HttpWebRequest.Create(myUri);  
  6. HttpWebRequest webReqStatus = (HttpWebRequest)myWebRequest;  
  7. NetworkCredential myNetworkCredential = new NetworkCredential(strUserName, strPassword);  
  8. CredentialCache myCredentialCache = new CredentialCache();  
  9. myCredentialCache.Add(myUri, "Digest", myNetworkCredential);  
  10. webReqStatus.PreAuthenticate = true;  
  11. webReqStatus.Credentials = myCredentialCache;  
  12. //webRequest.Headers.Add("authentication", "DIGEST");  
  13. webReqStatus.ContentType = "application/json";  
  14. //webRequest.Headers.Add("Authorization", "DIGEST");  
  15. webReqStatus.Method = "GET";  
  16. webReqStatus.KeepAlive = true;  
  17. //webReqHelloCash.Timeout = 10000;  
  18. //webReq.Headers.Add("cache-control", "no-cache");  
  19. PartouchePaymentRequest objReqStatus = new PartouchePaymentRequest();  
  20. objReqStatus.idFromClient = id;  
  21. objReqStatus.loginAgent = "7895";  
  22. objReqStatus.passwordAgent = "0000";  
  23. try  
  24. {  
  25. var _postDataPaymentStatus = JsonConvert.SerializeObject(objReqStatus);  
  26. byte[] bytedata = Encoding.ASCII.GetBytes(_postDataPaymentStatus);  
  27. webReqStatus.ContentLength = bytedata.Length;  
  28. Stream requestStream = webReqStatus.GetRequestStream();  
  29. requestStream.Write(bytedata, 0, bytedata.Length);  
  30. requestStream.Close();  
  31. HttpWebResponse webResp_PaymentStatus = (HttpWebResponse)webReqStatus.GetResponse();  
  32. resposeCode = (int)webResp_PaymentStatus.StatusCode;  
  33. using (var streamReader = new StreamReader(webResp_PaymentStatus.GetResponseStream()))  
  34. {  
  35. var result = streamReader.ReadToEnd();  
  36. }  
  37. }catch()  

Answers (3)