system.net.webclient post timeout

B

Blueparty

I am Java programmer who is forced to do something in .NET for the first
and, also, the last time in my life.

I have console application in vb.net which is retrieving data from
Tomcat web server using GET method, and uploading some other data using
POST method. I am using system.net.webclient and it works fine.

When I try to add basic authentication, GET still works fine, but POST
takes very long to complete. I have checked Tomcat logs, and request is
served swiftly, as normal, but vb.net application does not seem to be
aware of that, as if it is waiting for some kind of acknowledge.

I am adding NetworkCredential as webclient.credentials property.
I have also tried adding NetworkCredential to CredentialCache, and
setting webclient.credentials to CredentialCache, but there is no
improvement.

I repeat, everything works perfectly without authentication. Is there
any way to speed up POST request, apart from removing authentication ?

B
 
F

Family Tree Mike

Blueparty said:
I am Java programmer who is forced to do something in .NET for the first
and, also, the last time in my life.

I have console application in vb.net which is retrieving data from
Tomcat web server using GET method, and uploading some other data using
POST method. I am using system.net.webclient and it works fine.

When I try to add basic authentication, GET still works fine, but POST
takes very long to complete. I have checked Tomcat logs, and request is
served swiftly, as normal, but vb.net application does not seem to be
aware of that, as if it is waiting for some kind of acknowledge.

I am adding NetworkCredential as webclient.credentials property.
I have also tried adding NetworkCredential to CredentialCache, and
setting webclient.credentials to CredentialCache, but there is no
improvement.

I repeat, everything works perfectly without authentication. Is there
any way to speed up POST request, apart from removing authentication ?

B
.

Do you have your code in a try/catch block?

Does your code setting the credentials look something like this?

Dim client As New WebClient
client.Credentials = New NetworkCredential("user1", "password")

Can you post your code that is failing to give us some idea as to how we can
help you fix it?

Mike
 
B

Blueparty

Family said:
Do you have your code in a try/catch block?

Does your code setting the credentials look something like this?

Dim client As New WebClient
client.Credentials = New NetworkCredential("user1", "password")

Can you post your code that is failing to give us some idea as to how we can
help you fix it?

Mike


Thanks for your interest. Here are the relevant parts:

dim cred as new NetworkCredential("user","password")
dim credCache as new CredentialCache()
....
credCache.add(new Uri("http://192.168.0.2:8080/"),"Basic",cred)
....
function getHttpData(byval url as string,byref result as string) as integer
dim agent as WebClient=new WebClient()
agent.credentials=credCache
dim ret as integer=1
result=""
console.writeline("GET started")
try
result=agent.DownloadString(url)
ret=0
catch e as Exception
log.writeLine("GET method failed")
end try
console.writeline("GET finished")
return ret
end function

function putHttpData(byval url as string, byval sdata as string) as integer
dim agent as WebClient=new WebClient()
dim str3 as string=HttpUtility.urlEncode(sdata)
str3="alldata=" & str3
agent.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
agent.credentials=credCache
dim ret as integer=1
dim outData as string
console.writeline("POST started")
try
outData=agent.uploadString(url,str3)
ret=0
log.writeline(outData)
catch e as Exception
log.writeLine("POST method failed")
log.writeLine(e.toString())
end try
console.writeline("POST finished")
return ret
end function

I also tried without CredentialCache, supplyind NetworkCredential
directly, as I said. One more thing. IE does POST normaly, without any
delays, from the same machine and to the same site.

Function 'getHttpData' runs before 'putHttpData'. 'getHttpData' runs
normally, while 'putHttpData' is causing long delays. You can see
console output, so it is very clearly visible how long does any
operation take.

I also tried to change the order of

agent.Headers.Add("Content-Type", "application/x-www-form-urlencoded")

and

agent.credentials=credCache

but, nothing happened..

B
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top