vb.net - How to use HttpWebRequest to download file -


trying download file in code.

current code:

  dim uri new uribuilder     uri.username = "xxx"     uri.password = "xxx"     uri.host = "xxx"     uri.path = "xxx.aspx?q=65"     dim request httpwebrequest = directcast(webrequest.create(uri.uri), httpwebrequest)      request.allowautoredirect = true      request = directcast(webrequest.create(downloadurlin), httpwebrequest)     request.timeout = 10000     'request.allowwritestreambuffering = true      dim response httpwebresponse = nothing     response = directcast(request.getresponse(), httpwebresponse)     dim s stream = response.getresponsestream()      'write disk     dim fs new filestream("c:\xxx.pdf", filemode.create)      dim read byte() = new byte(255) {}     dim count integer = s.read(read, 0, read.length)     while count > 0         fs.write(read, 0, count)         count = s.read(read, 0, read.length)     end while      'close     fs.close()     s.close()     response.close() 

running code , checking response.responseuri indicates im being redirected login page , not pdf file.

for reason not authorising access missing im sending user name , password in uri? help

you don't need of code download file net use webclient class , downloadfile method


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -