https request



  • hi,
    wie kann ich unter mit c# einen post, oder get request an einen https server schicken??

    n8





  • danke, und was mach ich mit dem Verschlüsselungs Zeug, also SSL? Bei OpenSSL vorbei schauen, oder gibt es da was einfacheres?



  • Die WebRequest-Klasse und die WebResponse-Klasse verwenden SSL (Secure Sockets Layer) für die Kommunikation mit Hosts, die SSL automatisch unterstützen. Über die Verwendung von SSL wird von der WebRequest-Klasse auf Grundlage des zugewiesenen URI entschieden. Wenn der URI mit "https:" beginnt, wird SSL verwendet, wenn der URI mit "http:" beginnt, hingegen nicht.
    Das folgende Beispiel veranschaulicht die Verwendung von SSL.
    [Visual Basic]
    Dim MyURI As String = "https://www.contoso.com/"
    Dim Wreq As WebRequest = WebRequest.Create(MyURI)
    [C#]
    String MyURI = "https://www.contoso.com/";
    WebRequest WReq = WebRequest.Create(MyURI);



  • moin, cool, aber wo steht das bitte?
    hab leider mit google das nicht gefunden;-(
    n8



  • hi, so sende ich nun einen GET Request:

    using System;
    using System.Net;
    using System.Text;
    using System.IO;
    
    namespace HTTPS_Request
    {
    	/// <summary>
    	/// Summary description for Class1.
    	/// </summary>
    	class Class1
    	{
    		/// <summary>
    		/// The main entry point for the application.
    		/// </summary>
    		[STAThread]
    		static void Main(string[] args)
    		{
    			//
    			// TODO: Add code to start application here
    			//
    
    			// used to build entire input
    			StringBuilder sb  = new StringBuilder();
    
    			// used on each read operation
    			byte[]        buf = new byte[8192];
    
    			// prepare the web page we will be asking for
    			HttpWebRequest  request  = (HttpWebRequest)WebRequest.Create("https://www.myzone.at/webkeeper/Controller");
    
    			// execute the request
    			HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    
    			// we will read data via the response stream
    			Stream resStream = response.GetResponseStream();
    
    			string tempString = null;
    			int    count      = 0;
    
    			do
    			{
    				// fill the buffer with data
    				count = resStream.Read(buf, 0, buf.Length);
    
    				// make sure we read some data
    				if (count != 0)
    				{
    					// translate from bytes to ASCII text
    					tempString = Encoding.ASCII.GetString(buf, 0, count);
    
    					// continue building the string
    					sb.Append(tempString);
    				}
    			}
    			while (count > 0); // any more data to read?
    
    			// print out page source
    			Console.WriteLine(sb.ToString());
    			Console.Read();
    		}
    	}
    }
    

    respone bekomm ich:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="expires" content="0">
    <meta http-equiv="content-language" content="de">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="pragma" content="no-cache">
    <title>MyZone Login</title>
    <script language="javascript" src="/static/myzone/scripts/browserabfrage.js"TYPE
    ="text/javascript"></script>
    <!-- Script fuer  login -->
    <script language="JavaScript" type="text/javascript">
    <!--
            if( parent.frames.length > 0 )
                    parent.location.href = "/webkeeper/Controller?action=login";
    
            // Eingabecheck
            function checkForm()
            {
                    return true;
    
                    if (document.login.username.value == "")
                    {
                            alert ('Bitte geben Sie Ihren Benutzernamen ein!');
                            document.login.username.focus();
                            return false;
                    }
                    else
                    {
                            if (document.login.password.value == "")
                            {
                                    alert ('Bitte geben Sie Ihr Kennwort ein!');
                                    document.login.password.focus();
                                    return false;
                            }
                            else
                            {
                                    //document.login.submit();
                                    return true;
                            }
                    }
            }
    
            function Autofocus()
            {
                    document.forms[0].username.focus();
            }
    
    -->
    </script>
    </head>
    
    <body bgcolor="#FFFFFF" bottommargin="0" marginheight="0" marginwidth="0" rightm
    argin="0" leftmargin="0" topmargin="0" onload="Autofocus();" >
    <!-- Table f&uuml;r Header beginn  -->
    <table width=740 border=0 cellpadding=0 cellspacing=0 align="center">
      <tr>
        <td rowspan=3><img src="/static/myzone/images/tele2logo.gif" width=103 heigh
    t=93 alt="logo"></td>
        <td rowspan=3><img src="/static/myzone/images/myzone.gif" width=76 height=93
     alt="myzone"></td>
        <td rowspan=3><img src="/static/myzone/images/left.gif" width=65 height=93 a
    lt="left"></td>
        <td><img src="/static/myzone/images/bild1.gif" width=210 height=55 alt="bild
    1"></td>
        <td><img src="/static/myzone/images/bild2.gif" width=46 height=55 alt="bild2
    "></td>
        <td><img src="/static/myzone/images/bild3.gif" width=53 height=55 alt="bild3
    "></td>
        <td colspan=3><img src="/static/myzone/images/bild4.gif" width=129 height=55
     alt="bild4"></td>
        <td><img src="/static/myzone/images/bild5.gif" width=56 height=55 alt="bild5
    "></td>
        <td><img src="/static/myzone/images/space_clear.gif" width=2 height=55 alt="
    bild"></td>
      </tr>
      <tr bgcolor="#6699CC">
        <td rowspan=2><img src="/static/myzone/images/nav.gif" width=210 height=38 a
    lt="nav"></td>
        <td colspan="6" width=284 height=26>&nbsp;</td>
        <td width=2 height=26><img src="/static/myzone/images/right.gif" width=2 hei
    ght=26 alt="right"></td>
      </tr>
      <tr>
        <td colspan=7><img src="/static/myzone/images/unten.gif" width=286 height=12
     alt="unten"></td>
      </tr>
    </table>
    <!-- Table fuer Header end  -->
    <br>
    <form name="login" action="/webkeeper/Controller" method="post" >
    <input type=hidden name=action value=login>
    <input type="hidden" name="login" value="Anmelden">
    <input type=hidden name=brand value=myzone>
    <!-- Table fuer Login beginn  -->
    <table border="0" align="center" width="740" cellspacing="4" cellpadding="0">
    <!-- Text -->
            <tr>
                    <td width="175"><img src="/static/myzone/images/space_clear.gif"
     width="175" height="15" border="0"></td>
                    <td colspan="2" valign="top"><b>Herzlich Willkommen in UTA MyZon
    e!</b><br>
                    <br>
                                                            Dieser Bereich ist nur f
    |r UTA-Kunden zugdnglich. UTA MyZone ist ein exklusives Service zur Verwaltung I
    hrer UTA Services.
                            Sie kvnnen Neukonfigurationen und Dnderungen vornehmen,
    Statistiken und Online Zeiten abrufen, eMail Adressen und Weiterleitungsadressen
     eintragen und vieles mehr.<br><br>
                            <nobr>Zum Einloggen in UTA MyZone verwenden Sie bitte Ih
    ren bestehenden Benutzernamen und Ihr Kennwort.</nobr>
                                    </td>
            </tr>
            <!-- Login u. Pass Felder -->
            <tr><td colspan="3">&nbsp;</td></tr>
            <tr><td>&nbsp;</td><td colspan="2" align="left">Benutzername<br><input t
    ype=text name="username" size="10" class="kurz"></td></tr>
            <!-- Button "Anmelden" -->
            <tr><td>&nbsp;</td><td height="25" align="left" valign="bottom">Kennwort
    <br><input type="password" name="password" size="10" class="kurz">&nbsp;<INPUT T
    YPE="image" SRC="/static/myzone/buttons/anmelden.gif" onclick="return checkForm(
    )"></td>
            <!--<a href="javascript:checkForm()"><img src="/static/myzone/images/anm
    elden.gif" alt="Anmelden" width="121" height="15" border="0"></a></td> --></tr>
            <tr><td colspan="3">&nbsp;</td></tr>
            <tr>
                    <td width="175"><img src="/static/myzone/images/space_clear.gif"
     width="175" height="15" border="0"></td>
                    <td colspan="2"><a href="#" onclick="javascript:window.open('htt
    p://csstage.utalan.at/cs/servlet/ContentServer?pagename=UTA/Share/PasswortAbfrag
    eMyZone&abfrage=new','_blank','width=360,height=360');">Kennwort vergessen?</a><
    /td>
                    <!--td colspan="2"><a href="#" onclick="javascript:window.open('
    http://www.uta.at/ds?pagename=UTA/Share/PasswortAbfrageMyZone&abfrage=new','_bla
    nk','width=360,height=360');">Kennwort vergessen?</a></td-->
            </tr>
      </table>
    <!--table border="0" align="center" width="740" cellspacing="0" cellpadding="4">
    
            <tr>
        <td width="175"><img src="/static/myzone/images/space_clear.gif" width="175"
     height="15" border="0"></td>
                    <td align="left" valign="top" colspan="2" class="okbgcolor"><spa
    n class="weiss">
                            <b>Lieber UTA-Kunde!</b><br>
                            <br>
                            Aufgrund von Systemerweiterungen wird UTA MyZone zu folg
    enden Zeiten f|r Sie nicht verf|gbar sein:<br>
                            <br>
                            <div align="center"><b>
                            Freitag  8.10.04, 18.00 Uhr bis Montag  11.10.04, 8.00 U
    hr<br>
                            Freitag 15.10.04, 18.00 Uhr bis Montag 18.10.04, 8.00 Uh
    r</b></div><br>
                            Wir danken f|r Ihr Verstdndnis.</span>
                    </td>
            </tr>
    </table-->
    <!-- Table f&uuml;r Login end  -->
    </form>
    </body>
    </html>
    

    aber warum bekomm ich keinen http header?

    HTTP/1.0 200 OK
    Date: Mon, 11 Jul 2005 01:02:11 GMT
    Server: Apache/2.0.52 (Unix) mod_ssl/2.0.52 OpenSSL/0.9.7d mod_jk2/2.0.4
    Set-Cookie: JSESSIONID=CEEEFCD5A78F1152FD2F1DB7C6C2196A; Path=/webkeeper; Secure
    Content-Type: text/html; charset=ISO-8859-1
    Connection: close
    


  • ps.: kann ich den code in c++ auch verwenden als Managed C++, das wär ja fein!?

    n8


Anmelden zum Antworten