PLEASE HELP: using webresponse and webrequest

  • Thread starter Thread starter amine
  • Start date Start date
A

amine

I really need help on this please. I am writing an
application for an Ipaq and I am trying to enable the
application to connect to a DAV server which can is
basically an HTTP server that acts like an FTP server. I
used the following code

WebRequest req = WebRequest.Create (url);
req.Credentials = new NetworkCredential (username, pass);
WebResponse res = req.GetResponse();

the previous code caused the server to display the 401
error :Unauthorized (WebException).

So I thought maybe there is a proxy in the way so I used
the following code

WebRequest req = WebRequest.Create (url);
WebProxy curr_proxy = new WebProxy (url, true);
curr_proxy.Credentials = new NetworkCredential (username,
pass);
page_req.Proxy = curr_proxy;
WebResponse res = req.GetResponse();

that caused the same exact problem
I know for sure that the username and password are correct
cuz I can connect to that site through the browser (When
trying to access the site it prompts me for username and
password just as an HTTP server would.) and I know the
code works for other sites cuz I tried. (I didnt try an
password protected site though)

Oh ya and I also tried HttpWebRequest and HttpWebResponse
same problem

PLEASSE HELP. this is my senior thesis and I am basically
screwed if I dont figure this out soon

THANK YOU
 
I had exactly the same problem that you had. It doesn't
seem like the Credentials property of WebRequest or their
decendant classes are working for us either, and we've
tried them all.

As a work around, we ended up having to execute the
Net.exe process in order to pre-authenticate to the
server. Now I don't know if this will work on an Ipaq,
but you can try.

using System.Diagnostics;

Process process = new Process();
process = Process.Start(@"net",@"use \\server\share
password /user:domain\user");
while (process.HasExited != true); //for asynch use event
if (process.ExitCode == 0)
{
//do your stuff
}
else
{
//handle the error
}

Hope that helps.

PS: remember to close your share
 
Tom,

Your problem with FileWebRequest may not be the same as what amine is
seeing. You were trying to access a file on a network share - he's trying to
access a resource on a web server.

amine, first of all, can your code successfully access a web site which does
not require authentication? If not, then authentication is not your problem.
If so, then your problem is authentication with the DAV server.

In the latter case, try watching what's happening between the iPaq and the
server with a tool like ProxyTrace from http://pocketsoap.com. You'll want
to use the proxy code you added, but set the proxy to http://desktop:8080,
where ProxyTrace is running on machine desktop on port 8080. Carefully watch
the traffic between the server and the iPaq.

Good Luck,
John Saunders
Internet Engineer
(e-mail address removed)
 
Back
Top