Abdalla Omran

Abdalla Omran

  • NA
  • 334
  • 32k

Timout exception with HttpWebRequest.GetResponse()

Jul 30 2020 7:32 AM
Hi
I am getting always time out excption with httpwebrequest.GetResponse method .
 
first i am making a request Post
  1. private HttpWebRequest CreateRequest();  
after that getting the request in a veriable and serialliz to json
and this poinnt "request.GeResponse()" i am getting the exception time out .
i will be very glad for any kind of help .
  1. var request = CreateRequest();  
  2. try  
  3. {  
  4. using (var streamWriter = new StreamWriter(request.GetRequestStream()))  
  5. {  
  6. var json = JsonConvert.SerializeObject(pagesUrlJson,  
  7. new JsonSerializerSettings  
  8. {  
  9. ContractResolver =  
  10. new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }  
  11. });  
  12. streamWriter.Write(json);  
  13. }  
  14. using (var response = request.GetResponse())  
  15. {  
  16. using (var resultStream = response.GetResponseStream())  
  17. {  
  18. var reader = new StreamReader(  
  19. resultStream ?? throw new InvalidOperationException("Web response is null"));  
  20. var resultText = reader.ReadToEnd();  
  21. //here convert json to C#Object  
  22. }  

Answers (3)