WebRequest exception

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

WebRequest exception

alicya
Hello!

I have an empty iPhone Window-based Project created with MonoDevelop.
In the generated code, in the FinishedLaunching method I try to connect to the Twitter API using the following code:

        string url = "http://twitter.com/statuses/friends_timeline.xml";
        WebRequest request = WebRequest.Create(url);
        request.Method = WebRequestMethods.Http.Get;
        request.PreAuthenticate = true;
        request.Credentials = new NetworkCredential("*******", "*******");
        WebResponse response = request.GetResponse();

My username and password are correct Twitter credentials. I tried it out using HttpWebRequest and HttpWebResponse, but I constantly get the following error:

Unhandled Exception: System.Net.WebException: Error: ConnectFailure (Connection refused) ---> System.Net.Sockets.SocketException: Connection refused
  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00159] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net.Sockets/Socket_2_1.cs:1254
  at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x001ba] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebConnection.cs:184
....

If I try to connect to any other url, for example: http://google.com, specifying DefaultCredentials, or without using any credentials, I get the same error too.

Can you help me please?
Reply | Threaded
Open this post in threaded view
|

Re: WebRequest exception

dermotos
Hi,

try declaring your request object as a HttpWebRequest object, rather than a WebRequest object, like so:


HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.twitter.com");

Haven't tested it, but this is how i've always done it in .NET
Reply | Threaded
Open this post in threaded view
|

Re: WebRequest exception

alicya
In reply to this post by alicya
Hello!

Thank you for the response. I tried it with HttpWebRequest and HttpWebResponse, but I get the same error.

I further investigated the problem, and I found that when trying to execute "WebResponse response = request.GetResponse();", the response's IsMutuallyAuthenticated method throws System.NotImplementedException. So I think that this is the core of the problem.

Unhandled Exception: System.Net.WebException: The remote server returned an error: (401) Unauthorized.
  at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) [0x002d9] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1481
  at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) [0x00141] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1306

Thanks in advance for any help!
Reply | Threaded
Open this post in threaded view
|

Re: WebRequest exception

alicya
In reply to this post by alicya
I get the mentioned System.NotImplementedException in the WebResponse object's IsMutuallyAuthenticated method only when I try to reach sites that need authentication. So authentication might cause the problem.
Reply | Threaded
Open this post in threaded view
|

Re: WebRequest exception

Jeff Stedfast
Hi Alicya,

I've taken a look at the source code of HttpWebRequest and HttpWebResponse and it looks like PreAuthentication for web requests is implemented, it's just HttpWebResponse's IsMutuallyAuthenticated property that isn't.

That being said, could you submit a bug report to http://bugzilla.xamarin.com (preferably with a simple test case)?

Thanks,

Jeff

On Wed, Aug 10, 2011 at 4:49 AM, alicya <[hidden email]> wrote:
I get the mentioned System.NotImplementedException in the WebResponse
object's IsMutuallyAuthenticated method only when I try to reach sites that
need authentication. So authentication might cause the problem.

--
View this message in context: http://monotouch.2284126.n4.nabble.com/WebRequest-exception-tp3726510p3732346.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch


_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch