none
HttpWebRequest: Could not establish connection to network.

    Question

  • Dear Community,

    I really need your help in my Project becasue I don´t find any solution to my Problem. I´m desperate to gt thi working.
    In my .Net CF 3.5 Project I have to use a webservice that does not have a wsdl. So I have to use HttpWebRequest.
    This is my code:
    
    
    internal void SendSms()
            {
                HttpWebRequest req = 
    (HttpWebRequest)WebRequest.Create@"https://user:pass@api.sipgate.net/RPC2");
                req.Method = @"POST";
                req.ContentType = @"test/xml";
                req.ContentLength = Body.Length;
                using (Stream stream = req.GetRequestStream())
                using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
                {
                    writer.Write(Body);
                }
                using (Stream responseStream = req.GetResponse().GetResponseStream())
                using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8))
                {
                    string result = reader.ReadToEnd();
                }
            }


    When I call req.GetRequestStream I get the following Exception:

    "WebException was unhandled: Could not establish connection to network."

    StackTrace:

       at System.Net.HttpWebRequest.finishGetRequestStream()
       at System.Net.HttpWebRequest.GetRequestStream()
       at SipMSGate.UI.MainFormController.SendSms()
       at SipMSGate.UI.Form1.menuItem1_Click(Object sender, EventArgs e)
       at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
       at System.Windows.Forms.Application.Run(Form fm)
       at SipMSGate.Program.Main()

    Status:

    System.Net.WebExceptionStatus.ConnectFailure

    I´ve tried this on 2 Devices and also on the Emulator. On everyone I can use the IE to browse the Internet and all other Applications are able to use the Internet Connection. I´ve also tried this code in an .Net CF 2.0 Project with the same Exception.

    Can someone please help me and tell me what´s wrong with my code or what I´ve to do to get it work?

    Thank you so much

    dragi
    Tuesday, December 29, 2009 10:53 AM

Answers

All replies