如何打开与使用GoogleOauth2Service的主机的连接

时间:2019-04-18 15:01:06

标签: c# sockets single-sign-on

我使用套接字打开与使用Google SSO的主机的连接,但是,我不知道如何提供我的Google凭据并将其与套接字一起发送以访问主页。

public static void Start(){

        byte[] bytes = new byte[2097152];
        try
        {
            IPHostEntry host = Dns.GetHostEntry("myhost.net");
            IPAddress ipAddress = host.AddressList[0];
            IPEndPoint remoteEP = new IPEndPoint(ipAddress, 80);

            Socket sender = new Socket(ipAddress.AddressFamily,
            SocketType.Stream, ProtocolType.Tcp);

            try
            {
                sender.Connect(remoteEP);

                Console.WriteLine("Socket connected to {0}",
                    sender.RemoteEndPoint.ToString());

                // Encode the data string into a byte array.    
                byte[] msg = Encoding.ASCII.GetBytes("GET /Home HTTP/1.1\r\n" + "Host: myhost.net\r\n" + "Content-Length: 0\r\n" + "\r\n");
                int bytesSent = sender.Send(msg);

                // Receive the response from the remote device.    
                int bytesRec = sender.Receive(bytes);
                Console.WriteLine("Echoed test = {0}",
                    Encoding.ASCII.GetString(bytes, 0, bytesRec));

                // Release the socket.    
                sender.Shutdown(SocketShutdown.Both);
                sender.Close();
            }
            catch (ArgumentNullException ane)
            {
                Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
            }
            catch (SocketException se)
            {
                Console.WriteLine("SocketException : {0}", se.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine("Unexpected exception : {0}", e.ToString());
            }
        }
        catch (Exception e) {

            Console.WriteLine(e.ToString());

        }

0 个答案:

没有答案