Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

objWebClient.DownloadData - The remote server returned an error: (400) Bad Request.

Avatar of Starr Duskk
Starr DuskkFlag for United States of America asked on
Microsoft IIS Web ServerASP.NET
1 Comment1 Solution1064 ViewsLast Modified:
There are two production servers. It works on one and not the other. So I'm thinking one must have a different setting.

            Dim objWebClient As New WebClient()
            Dim objUTF8 As New UTF8Encoding()
            Dim strOutput As String = objUTF8.GetString(objWebClient.DownloadData(strUrl))

I am using this to scrape a screen, and it works fine locally and on my development site, but on my production site it errors with the message:

The remote server returned an error: (400) Bad Request.

Is there some setting in IIS6 that blocks use of this type of method?

I need to receive the file as a string so that I can edit the relative paths to the style sheets so they can be opened from an email attachment.


I tried this method, but it doesn't give me a string to manipulate. I haven't yet tested it on the production website, so it may not work either.
            Dim myHttpWebRequest As System.Net.HttpWebRequest = CType(System.Net.WebRequest.Create(strUrl), System.Net.HttpWebRequest)
            Dim myHttpWebResponse As System.Net.HttpWebResponse = CType(myHttpWebRequest.GetResponse(), System.Net.HttpWebResponse)
            Dim receiveStream As Stream = myHttpWebResponse.GetResponseStream()
            Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
            Dim readStream As New StreamReader(receiveStream, encode)
            Dim fs As New FileStream(UniquefileName, FileMode.Create)
            Dim BWriter As New BinaryWriter(fs, Encoding.GetEncoding("UTF-8"))
            BWriter.Write(readStream.ReadToEnd())
            readStream.Close()
            BWriter.Close()
            fs.Close()
            myHttpWebResponse.Close()

Any ideas how to receive the above string value before writing?
ASKER CERTIFIED SOLUTION
Avatar of Starr Duskk
Starr DuskkFlag of United States of America imageASP.NET VB.NET Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answers