473,322 Members | 1,526 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,322 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 2703
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.