另外一个关于发包的例子

来源:互联网 发布:图片编辑软件有哪些 编辑:程序博客网 时间:2024/06/05 19:01
using System;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;

        
public string GetTicket(string ChallengeString)
        
{
            
string getTicketCmd = "GET https://login.passport.com/login2.srf HTTP/1.1 " + "Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in="+this._userName.Replace("@""%40"+ ",pwd=" + this._password + "," + ChallengeString + " " + "Host: login.passport.com ";
            Socket socket 
= new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 
1);
            IPEndPoint ipepServer 
= new IPEndPoint(IPAddress.Parse("10.0.0.172"),80);
            socket.Connect(ipepServer);
            
if (socket != null)
            
{
                Encoding ASCII 
= Encoding.ASCII;
                Byte[] sendCmd 
= ASCII.GetBytes(getTicketCmd);
                
int sendState = socket.Send(sendCmd, sendCmd.Length, 0);
                UTF8Encoding UTF8 
= new UTF8Encoding();
                Byte[] RecvBytes 
= new byte[1024];
                
string data = "";
                
int bytes = 0;
                bytes 
= socket.Receive(RecvBytes, RecvBytes.Length, 0);
                data 
= UTF8.GetString(RecvBytes, 0, bytes);
                
string[] tmpDataList = data.Split(new char[] ''' });
                socket.Shutdown(SocketShutdown.Both);
                socket.Close();
                
return tmpDataList[1];
            }

            
else
            
{
                
return "";
            }

 
原创粉丝点击