473,378 Members | 1,162 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,378 software developers and data experts.

WebRequest and WebResponse not working correctly

Dear Sirs,

I am using the WebRequest and WebResponse methods to download documents
from a webstore, the code is running sucessfully and the documents are being
downloaded but they are corupted. I have pasted the code below. What am I
doing wrong?

Regards,
Yahya

Private Sub GetAttachment(ByVal strAttachmentName As String, ByVal strSrcURI
As String)

Dim Request As System.Net.HttpWebRequest

Dim Response As System.Net.HttpWebResponse

Dim MyCredentialCache As System.Net.CredentialCache

Dim strPassword As String

Dim strDomain As String

Dim strUserName As String

Dim bytes() As Byte

Dim ResponseStream As System.IO.Stream

Dim sr As System.IO.StreamReader

Dim strDoc As String

Dim sw As System.IO.StreamWriter

Try

strUserName = "user"

strPassword = "password"

strDomain = "domain"

MyCredentialCache = New System.Net.CredentialCache

MyCredentialCache.Add(New System.Uri(strSrcURI), _

"NTLM", _

New System.Net.NetworkCredential(strUserName, strPassword,
strDomain) _

)

Request = CType(System.Net.WebRequest.Create(strSrcURI), _

System.Net.HttpWebRequest)

Request.Credentials = MyCredentialCache

Request.Method = "GET"

Request.Headers.Add("Translate", "f")

Response = CType(Request.GetResponse(),
System.Net.HttpWebResponse)

ResponseStream = Response.GetResponseStream()

sr = New System.IO.StreamReader(ResponseStream, _

System.Text.Encoding.UTF8)

'urn:schemas:mailheader:message-id

sw = New IO.StreamWriter("C:\temp\" & strAttachmentName)

strDoc = sr.ReadToEnd

sw.WriteLine(strDoc)

sw.Close()

MessageBox.Show("Item stream:")

MessageBox.Show("")

MessageBox.Show(sr.ReadToEnd())

Response.Close()

ResponseStream.Close()

sr.Close()

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End Sub


Nov 21 '05 #1
0 806

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

Similar topics

1
by: Peter | last post by:
Hi I am trying to do very simple http client that requires a login, copy cookie snet by a server and does a request with the cookies. WebRequest->CookieContainer/WebResponse->Cookies does not...
2
by: gizmo | last post by:
Hi, I'm using the following code to request the html source from the quoted site. ...... string url = "http://www1.soccerstand.com/"; WebRequest webRequest = WebRequest.Create(url);...
12
by: ThyRock | last post by:
I am working on a WebRequest accessing the US Postal Service WebTools test API. This service uses a DLL file (ShippingAPITest.dll) with a query string which includes XML. The web service accepts...
0
by: Gordon | last post by:
I use the following code to get source HTML. The second line seems to work when I get no response from a site. However, I want to stop the request if it's taking more than 20 - 30 seconds. I can't...
2
by: kkb | last post by:
Hello! First, I'm sorry because of my english... I'll try to be understandable! I've got a strange problem using .NET 2003 C# and I haven't figured it out for a long time. I'm implementing an...
1
by: Mr Flibble | last post by:
OK I logon to a web site and I manage to get an SMSESSION cookie that I then store in a variable called _session (a class scoping variable). I do this by calling a logon URL and setting a cookie...
2
by: Zytan | last post by:
I know that WebRequest.GetResponse can throw WebException from internet tutorials. However in the MSDN docs: http://msdn2.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx It...
4
by: CindyH | last post by:
Hi I'm trying to use webrequest - webresponse to post a stream. I have set up a simple test with one aspx form holding the post code and trying to get another aspx form to receive the post on...
4
by: CindyH | last post by:
Hi - hope someone can help with this - this code was working for a while in the 'real' code and then suddenly stopped - not sure what happen. I made two simple forms on localhost to try to test...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.