473,396 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to control the time-out of a webclient request?

I am using webclient to retrieve data from a web site. How do I control the
time-out
of this request?
Nov 22 '05 #1
8 2708
Hi,

The WebClient class does not offer any property where u can set the timeout
period. If possible use the HttpWebrequest instead. The Webclient insternally
uses the webrequest class. In HttpWebrequest you can set the request timeout
property.

"Kueishiong Tu" wrote:
I am using webclient to retrieve data from a web site. How do I control the
time-out
of this request?

Nov 22 '05 #2

Thank you for your reply. Could you give me coding sample how to use
httpwebrequest and set the time-out property?

Nov 22 '05 #3
Hi,

Here is a sample code:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Endpoint);
//Endpoint is the URL to which u are making the request.
request.Method = "POST";
request.Credentials = CredentialCache.DefaultCredentials;
request.ContentType = "text/xml"; //depending on the data u are sending this
will change.
request.Timeout=<value in milliseconds>;

---
Bharat Biyani (bs*@orcim.com)
http://www.orcim.com

"Kueishiong Tu" wrote:

Thank you for your reply. Could you give me coding sample how to use
httpwebrequest and set the time-out property?

Nov 22 '05 #4
Thank you very much for the reply. Could you give me coding sample on getting
the response. I have difficulty in getting the response.
Nov 22 '05 #5
Hi,

Here is how u get the response.

try
{
// send the request and get the response
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException e)
{
// handle exception
}
Stream responseStream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
string responseText = streamReader.ReadToEnd();
response.Close();

---
Bharat Biyani (bs*@orcim.com)
http://www.orcim.com

"Kueishiong Tu" wrote:
Thank you very much for the reply. Could you give me coding sample on getting
the response. I have difficulty in getting the response.

Nov 22 '05 #6
I am still not getting the response. I think the problem has something to do
with
the way of making the request.

I have a uriString which looks like

uriString =
S"http://trade1.masterlink.com.tw/futures/QueryOrder.jsp?queryDate=20040811&actno=11111111&p wd=1234567890&idnoR11111111s&isPreorder=NO"

I pass the urlString to webclient

myWebClient->UploadData(uriString, postArray);

I get the response back without any problem.

Now I pass the same string to HttpWebrequest

HttpWebRequest *request =
dynamic_cast<HttpWebRequest*> (WebRequest::Create(uriString));

However I do not get any reponse and get time-out exception.

What is wrong here?

Nov 22 '05 #7
Hi,

Can u give the complete code...I tried that URL on the browser and the
browser is giving 500 internal error. So it means that prior to this u need
to do some other things also like logging in etc.

---
Bharat Biyani (bs*@orcim.com)
http://www.orcim.com

"Kueishiong Tu" wrote:
I am still not getting the response. I think the problem has something to do
with
the way of making the request.

I have a uriString which looks like

uriString =
S"http://trade1.masterlink.com.tw/futures/QueryOrder.jsp?queryDate=20040811&actno=11111111&p wd=1234567890&idnoR11111111s&isPreorder=NO"

I pass the urlString to webclient

myWebClient->UploadData(uriString, postArray);

I get the response back without any problem.

Now I pass the same string to HttpWebrequest

HttpWebRequest *request =
dynamic_cast<HttpWebRequest*> (WebRequest::Create(uriString));

However I do not get any reponse and get time-out exception.

What is wrong here?

Nov 22 '05 #8
Try this url

http://trade7.masterlink.com.tw/futures/QuotePrice.jsp

you should be able to run this url on the browser.

The webclient call gets the response. However the httpwebrequest gets
System.Net.WebException.

Nov 22 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
5
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
3
by: _DS | last post by:
Problem with mapping a directory tree to a tree control: It takes a while to recurse subdirs and map them to nodes. This is solved in some books I've seen (MacDonald, Albahari) by reading the...
5
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
0
by: pabloazorin | last post by:
I developed a Date Picker web control using C# and .net framework 1.1 I added my control to Visual Studio 2003 IDE toolbar. When I drag and drop my control to design web page, the control renders...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
0
by: fredloh | last post by:
i have a tab control on my form. i then have several microsoft date and time picker control on the tab control. when i select a date on any of the date and time picker control, the result of the...
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.