HTTPWebResponse ArgumentException

  • Thread starter Simon Wilkinson via DotNetMonster.com
  • Start date

S

Simon Wilkinson via DotNetMonster.com

I've tried for many many hours to figure this out, but have finally
admitted defeat... please help!

I am trying to use HTTPWebRequest/HTTPWebResponse to download a file from a
webserver using the following code, with VB.NET 1.1 (CF):

Try

Dim wr As HttpWebRequest = CType(WebRequest.Create(strWebPath &
"manifest.txt"), HttpWebRequest)
wr.KeepAlive = False

Dim ws As HttpWebResponse = CType(wr.GetResponse(), HttpWebResponse)

Dim streamResponse As Stream = ws.GetResponseStream()
Dim streamRead As New StreamReader(streamResponse)
strWebVersion = streamRead.ReadToEnd()

Catch ex As System.ArgumentException
MessageBox.Show("Web Error:" + Err.Description)
Catch ex As System.Net.WebException
MessageBox.Show("Web Error:" + Err.Description)
Catch ex As Exception
MessageBox.Show("Web Error:" + Err.Description)
End Try

When I set strWebPath = "http://machinename/foldername/" then I (and
another tester in another location) get an unhandled "managed
ArgumentException" - Argument 'Prompt' cannot be converted to type 'String'.

Oddly, when I set strWebPath = "http://IPaddress/foldername/" then I can
successfully download the file (although the tester in the other location
gets the same error).

If I use MsgBox to step through the code to discover where the error is
(sorry, probably not the best way to do this!), it falls over on the line
that declares and returns the HTTPWebResponse.

The web server (IIS) definitely has read permissions for the relevant
folder (indicated by "foldername"), anonymous access is ticked, the same
error is found using emulator or iPAQ.

Please can someone give me some ideas on what I should try?
 
Ad

Advertisements

A

Arun

Try Changing the HTTPWebRequest like this

strWeb­Path = strWeb­Path & "manifest.txt";
Dim wr As HttpWebRequest =
(HttpWebRequest)WebRequest.Create(strWeb­Path);

Hope this helps,

Regards,
Arun.
 
Ad

Advertisements

S

Simon Wilkinson via DotNetMonster.com

Thanks for the help Arun. I've sorted this out now, so thought I would just
provide a few more details on what happened, what I did. My final code was:

Try
Dim uri As Uri = New Uri(strWebPath & "manifest.txt")
Dim wr As HttpWebRequest = CType(WebRequest.Create(uri), HttpWebRequest)
Dim ws As HttpWebResponse = CType(wr.GetResponse(), HttpWebResponse)
Dim streamResponse As Stream = ws.GetResponseStream()
Dim streamRead As New StreamReader(streamResponse)
strManifestText = streamRead.ReadToEnd()

streamRead.Close()
streamResponse.Close()
ws.Close()

Catch ex As Exception
MessageBox.Show("Web Error:" + Err.Description)
End Try

This code works with or without any CF service packs. There was no issues
where it worked with IP address, but not with a computer name (my problem
was that I don't have a domain controller).

The problem I was actually having was that I was getting the value of
strWebPath from a text file that on the PDA, so that the PDA user could set
this value accordingly. When the PDA first had the application installed,
the default value I hardcoded into this file worked fine, but as soon as
the value was changed on the PDA it stopped working.

When the value was changed on the PDA, no matter what I did, it would
always put a carriage return at the end of the string. It would seem there
is no way to prevent this, so the solution was simply to handle it before
doing the HTTPWebRequest/HTTPWebResponse:

strWebPath = strWebPath.Replace(Chr(13) & Chr(10), "")

Given the amount of time I spent trying to figure out something so simple,
hopefully someone else might be spared from suffering this text file issue.
 

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