Hello,
I try to use HttpWebRequest
in c#/Mono on my nokia 770 (in fact, I want to use Web Services).
The first part of the below
program which use TcpClient() works very well: I can get a page from a distant
server.
But with the second part,
which use HttpWebRequest, fails with a 'time out" exception at the
request.GetResponse() :
…
Unhandled Exception:
System.Net.WebException: The request timed out
in <0x001b8>
System.Net.HttpWebRequest:EndGetResponse (IAsyncResult asyncResult)
in <0x0007f> System.Net.HttpWebRequest:GetResponse
()
in <0x003df>
Http.Requete:Main (System.String[] args)
/ $
I installed the
mono-nokia_1.1.13-1_arm.deb package and copied the 'machine.config' file to the
'/var/lib/install/usr/etc/mono/1.0/' directory.
This program works very well
on windows with mono-1.1.13.
Is it a bug? Did i miss something? Does somebody have any idea?
Thanks,
Marc.
// ------ httpConnectTest.cs
------------------------
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
namespace NetworkTest
{
class Request
{
static void Main(string[] args)
{
try
{
//------- First part with TcpClient.GetStream() ip connection
String server = "192.168.0.2";
Int32 port = 80;
String message = "GET / HTTP/1.0\r\r\n\n";
TcpClient client = new TcpClient(server, port);
Byte[] data =
""
NetworkStream stream = client.GetStream();
stream.Write(data, 0, data.Length);
// Receive the TcpServer.response.
string returndata="";
byte[]
octetsRecus;
string result="";
do {
octetsRecus= new byte[client.ReceiveBufferSize];
stream.Read(octetsRecus, 0, (int) client.ReceiveBufferSize);
returndata = System.Text.Encoding.ASCII.GetString(octetsRecus);
result+=returndata;
} while (octetsRecus[0]!=0);
Console.WriteLine("Received: \n {0}",result);
client.Close();
// ------ Second part with
HttpWebRequest.GetResponse() ip connection
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create("http://192.168.0.2:80");
Console.WriteLine ("\nExecute the request...");
HttpWebResponse response = (HttpWebResponse) request.GetResponse(); //<--
here is the 'time out' exception
Console.WriteLine ("Content length is {0}", response.ContentLength);
StreamReader Sr = new StreamReader(response.GetResponseStream());
String result1 = Sr.ReadToEnd();
Console.WriteLine ("Received: \n {0}",result1);
Sr.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception: {0}", e);
}
Console.WriteLine("\n Press Enter to continue...");
Console.Read();
}
}
}
// end of program
_______________________________________________ maemo-developers mailing list [email protected] https://maemo.org/mailman/listinfo/maemo-developers
