TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Suresh Shewale
NA
179
3.5k
How to pull all 100 pages from 3rd party API by webrequest
Dec 24 2019 6:01 AM
I created one C# web service where
1. First i finds no of pages for that date range
2. After that in Loop I made Page request after 3rd request i Got 524 Error
private string postPaymentRequestToGateway(String queryUrl, String urlParam)
{
String message = "";
StreamWriter myWriter = null;// it will open a http connection with provided url
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
WebRequest objRequest = WebRequest.Create(queryUrl);//send data using objxmlhttp object
WriteToFile("Request Time Before Response " + System.DateTime.Now);
objRequest.Method = "POST";
try
{
objRequest.ContentType = "application/x-www-form-urlencoded";//to set content type
myWriter = new System.IO.StreamWriter(objRequest.GetRequestStream());
myWriter.Write(urlParam);//send data
myWriter.Close();//closed the myWriter objec=-[ TR
// Getting Response
//using (System.Net.HttpWebResponse objResponse = (System.Net.HttpWebResponse)objRequest.GetResponse())
using (WebResponse objResponse = objRequest.GetResponse())
//receive the responce from objxmlhttp object
{
//Thread.Sleep(10000);
WriteToFile("Request Time After Response " + System.DateTime.Now);
using (System.IO.StreamReader sr = new System.IO.StreamReader(objResponse.GetResponseStream()))
{
message = sr.ReadToEnd();
sr.Close();
}
//WriteToFile("Request Time After Response Message " + message);
}
}
catch (Exception exception)
{
WriteToFile("Inner Exception Stack" + exception.StackTrace);
WriteToFile("Inner Exception " + exception.InnerException.Message);
}
finally
{
objRequest.Abort();
myWriter.Close();//closed the myWriter object//05April2019
}
return message;
}
What I have tried:
For this I added objRequest.Abort(); in finally method
I tried various options but I Cant find solution .
Error in objRequest.GetResponse()) where Response takes more time after third pages
and then timeout error .
Can anyone tell me how to resolve this problem?.......
Reply
Answers (
1
)
How to Create REST service in .NET
Asp.net MVC using Web API perform curd operations