System.Text.StringBuilder html
=
new
System.Text.StringBuilder(
2000
);
string Url = " http://pub.*****.com/special/paihang.dat " ;
Request1 = (HttpWebRequest)WebRequest.Create(Url);
Response1 = (HttpWebResponse) Request1.GetResponse();
Stream stream = ((HttpWebResponse)Request1.GetResponse()).GetResponseStream();
Result = new StreamReader(stream,System.Text.Encoding.GetEncoding( " GB2312 " )).ReadToEnd();
string [] aa = Result.Split( ' \n ' );
string [] a = new string [ 4 ];
string Url = " http://pub.*****.com/special/paihang.dat " ;
Request1 = (HttpWebRequest)WebRequest.Create(Url);
Response1 = (HttpWebResponse) Request1.GetResponse();
Stream stream = ((HttpWebResponse)Request1.GetResponse()).GetResponseStream();
Result = new StreamReader(stream,System.Text.Encoding.GetEncoding( " GB2312 " )).ReadToEnd();
string [] aa = Result.Split( ' \n ' );
string [] a = new string [ 4 ];
public
static
string
SendHttpSoapRequest (
string
soapMessage ,
int
timeOutSec,IACT_API api )
{
//是否不要用SSL,true表示不用ssl
bool isByPassSSL = false;
if ( api == IACT_API.IACT_HotelGenAvail || api == IACT_API.IACT_HotelDetAvail || api == IACT_API.IACT_Ping || api == IACT_API.IACT_HotelRateCalendar )
{
isByPassSSL = true;
}
if ( !isByPassSSL )
{
ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
}
String Result = "";
StreamWriter myWriter = null;
//原始的代码
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(HttpRequestSender.BuildURL ( api,isByPassSSL));
objRequest.Method = "POST";
objRequest.ContentType = "text/xml";
objRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1)";
objRequest.Headers.Add("SOAPAction","\"\"");
//请求中设置压缩
objRequest.Headers.Add( "Accept-Encoding","parameter to gzip");
objRequest.Timeout = timeOutSec * 1000;
try
{
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(soapMessage);
}
catch (Exception e)
{
throw ( e );
}
finally
{
if(myWriter!=null)
{
myWriter.Close();
}
}
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
gzip时解压#region gzip时解压
//判断是否是gzip的压缩格式
if ( objResponse.Headers["Content-Encoding"] == "gzip" )
{
Stream GzipStream = new GZipInputStream (objResponse.GetResponseStream() );
MemoryStream UnZipStream = new MemoryStream();
int size = 2048;
byte [] writeData = new byte[size];
while ( true )
{
size = GzipStream.Read ( writeData,0,size );
if ( size>0 )
{
UnZipStream.Write ( writeData,0,size );
}
else
{
break;
}
}
UnZipStream.Position = 0;
using ( StreamReader sr = new StreamReader ( UnZipStream ) )
{
Result = sr.ReadToEnd();
sr.Close();
GzipStream.Close ();
}
}
#endregion
未压缩时#region 未压缩时
//如果没有压缩
else
{
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()) )
{
Result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
}
#endregion
if ( ( int )objResponse.StatusCode != 200 )
{
throw ( new HttpApplicationException () );
}
//删除Soap header和Soap Body中的默认的命名空间
//System.Diagnostics.Debug.Write ( Result );
Result = Result.Replace ( "xmlns=\"http://www.*****.com\"" , "" );
// objResponse.Close ();
return Result;
}
private static string BuildURL ( IACT_API api , bool byPassSSL )
{
string url = "<protocol>//<server>/pub/agent.dll?qscr=<message>&tpid=<tpid>";
//获取server的ip
url = url.Replace ( "<server>",Config.SERVER );
//获取tpid
url = url.Replace ( "<tpid>",Config.TPID );
switch ( api )
{
case IACT_API.IACT_HotelGenAvail:
url = url.Replace ( "<protocol>","http:");
url = url.Replace ( "<message>","haga");
break;
case IACT_API.IACT_HotelDetAvail:
url = url.Replace ( "<protocol>","http:" );
url = url.Replace ( "<message>" ,"hada" );
break;
case IACT_API.IACT_Ping:
url = url.Replace ( "<protocol>","http:" );
url = url.Replace ( "<message>" ,"hapg" );
break;
case IACT_API.IACT_BookHold:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>","https:" );
url = url.Replace ( "<message>","habh" );
break;
case IACT_API.IACT_BookCommit:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>","https:" );
url = url.Replace ( "<message>","habc" );
break;
case IACT_API.IACT_BookRollback :
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","habr" ) ;
break;
case IACT_API.IACT_HotelRateCalendar:
url = url.Replace ( "<protocol>","http:" );
url = url.Replace ( "<message>","harc" );
break;
case IACT_API.IACT_Retrieve:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hart" ) ;
break;
case IACT_API.IACT_HotelCancel:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hahc" ) ;
break;
case IACT_API.IACT_HotelModifyGenAvail:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hamg" ) ;
break;
case IACT_API.IACT_HotelModifyDetAvail:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hamd" ) ;
break;
case IACT_API.IACT_HotelModifyHold:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hamh" ) ;
break;
case IACT_API.IACT_HotelFinancialAdjustment:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hafa" ) ;
break;
case IACT_API.IACT_HotelOptionChange:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","haoc" ) ;
break;
}
return url;
}
/**/ /// <summary>
/// 用于spoofer
/// </summary>
/// <param name="api"></param>
/// <param name="byPassSSL"></param>
/// <param name="soapMessage"></param>
/// <returns></returns>
private static string BuildURL ( IACT_API api , bool byPassSSL , string soapMessage)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml ( soapMessage );
string echoInfo = xmlDoc.SelectSingleNode ( "//EchoInfo" ).InnerText;
string url = "<protocol>//<server>/pub/agent.dll?qscr=<message>&tpid=<tpid>";
//获取server的ip
url = url.Replace ( "<server>",Config.SERVER );
//获取tpid
url = url.Replace ( "<tpid>",Config.TPID );
switch ( api )
{
case IACT_API.IACT_HotelGenAvail:
//url = url.Replace ( "<protocol>","http:");
//url = url.Replace ( "<message>","haga");
url = "He/GenAvail/GenAvail.aspx?case="+echoInfo;
break;
case IACT_API.IACT_HotelDetAvail:
url = url.Replace ( "<protocol>","http:" );
url = url.Replace ( "<message>" ,"hada" );
url = "http://****//DetAvail/DetAvail.aspx?case="+echoInfo;
break;
case IACT_API.IACT_Ping:
url = url.Replace ( "<protocol>","http:" );
url = url.Replace ( "<message>" ,"hapg" );
break;
case IACT_API.IACT_BookHold:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>","https:" );
url = url.Replace ( "<message>","habh" );
url = "http://****//BookHold/BookHold.aspx?case="+echoInfo;
break;
case IACT_API.IACT_BookCommit:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>","https:" );
url = url.Replace ( "<message>","habc" );
url = "http://****//Commit-Roll/Commit-Roll.aspx?case="+echoInfo;
break;
case IACT_API.IACT_BookRollback :
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","habr" ) ;
url = "http://****//Commit-Roll/Commit-Roll.aspx?case="+echoInfo;
break;
case IACT_API.IACT_HotelRateCalendar:
url = url.Replace ( "<protocol>","http:" );
url = url.Replace ( "<message>","harc" );
break;
case IACT_API.IACT_Retrieve:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hart" ) ;
url = "http://****//Retrieve/Retrieve.aspx?case="+echoInfo;
break;
case IACT_API.IACT_HotelCancel:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hahc" ) ;
url = "http://****//Cancel/Cancel.aspx?case="+echoInfo;
break;
case IACT_API.IACT_HotelModifyGenAvail:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hamg" ) ;
url = "http://****//ModifyGenAvail/ModifyGenAvail.aspx?case="+echoInfo;
break;
case IACT_API.IACT_HotelModifyDetAvail:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hamd" ) ;
url = "http://****//ModifyDetAvail/ModifyDetAvail.aspx?case="+echoInfo;
break;
case IACT_API.IACT_HotelModifyHold:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hamh" ) ;
url = "http://****//ModifyHold/ModifyHold.aspx?case="+echoInfo;
break;
case IACT_API.IACT_HotelFinancialAdjustment:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hafa" ) ;
break;
case IACT_API.IACT_HotelOptionChange:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","haoc" ) ;
url = "http://****//OptionChange/OptionChange.aspx?case="+echoInfo;
break;
}
return url;
}
{
//是否不要用SSL,true表示不用ssl
bool isByPassSSL = false;
if ( api == IACT_API.IACT_HotelGenAvail || api == IACT_API.IACT_HotelDetAvail || api == IACT_API.IACT_Ping || api == IACT_API.IACT_HotelRateCalendar )
{
isByPassSSL = true;
}
if ( !isByPassSSL )
{
ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
}
String Result = "";
StreamWriter myWriter = null;
//原始的代码
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(HttpRequestSender.BuildURL ( api,isByPassSSL));
objRequest.Method = "POST";
objRequest.ContentType = "text/xml";
objRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1)";
objRequest.Headers.Add("SOAPAction","\"\"");
//请求中设置压缩
objRequest.Headers.Add( "Accept-Encoding","parameter to gzip");
objRequest.Timeout = timeOutSec * 1000;
try
{
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(soapMessage);
}
catch (Exception e)
{
throw ( e );
}
finally
{
if(myWriter!=null)
{
myWriter.Close();
}
}
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
gzip时解压#region gzip时解压
//判断是否是gzip的压缩格式
if ( objResponse.Headers["Content-Encoding"] == "gzip" )
{
Stream GzipStream = new GZipInputStream (objResponse.GetResponseStream() );
MemoryStream UnZipStream = new MemoryStream();
int size = 2048;
byte [] writeData = new byte[size];
while ( true )
{
size = GzipStream.Read ( writeData,0,size );
if ( size>0 )
{
UnZipStream.Write ( writeData,0,size );
}
else
{
break;
}
}
UnZipStream.Position = 0;
using ( StreamReader sr = new StreamReader ( UnZipStream ) )
{
Result = sr.ReadToEnd();
sr.Close();
GzipStream.Close ();
}
}
#endregion
未压缩时#region 未压缩时
//如果没有压缩
else
{
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()) )
{
Result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
}
#endregion
if ( ( int )objResponse.StatusCode != 200 )
{
throw ( new HttpApplicationException () );
}
//删除Soap header和Soap Body中的默认的命名空间
//System.Diagnostics.Debug.Write ( Result );
Result = Result.Replace ( "xmlns=\"http://www.*****.com\"" , "" );
// objResponse.Close ();
return Result;
}
private static string BuildURL ( IACT_API api , bool byPassSSL )
{
string url = "<protocol>//<server>/pub/agent.dll?qscr=<message>&tpid=<tpid>";
//获取server的ip
url = url.Replace ( "<server>",Config.SERVER );
//获取tpid
url = url.Replace ( "<tpid>",Config.TPID );
switch ( api )
{
case IACT_API.IACT_HotelGenAvail:
url = url.Replace ( "<protocol>","http:");
url = url.Replace ( "<message>","haga");
break;
case IACT_API.IACT_HotelDetAvail:
url = url.Replace ( "<protocol>","http:" );
url = url.Replace ( "<message>" ,"hada" );
break;
case IACT_API.IACT_Ping:
url = url.Replace ( "<protocol>","http:" );
url = url.Replace ( "<message>" ,"hapg" );
break;
case IACT_API.IACT_BookHold:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>","https:" );
url = url.Replace ( "<message>","habh" );
break;
case IACT_API.IACT_BookCommit:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>","https:" );
url = url.Replace ( "<message>","habc" );
break;
case IACT_API.IACT_BookRollback :
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","habr" ) ;
break;
case IACT_API.IACT_HotelRateCalendar:
url = url.Replace ( "<protocol>","http:" );
url = url.Replace ( "<message>","harc" );
break;
case IACT_API.IACT_Retrieve:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hart" ) ;
break;
case IACT_API.IACT_HotelCancel:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hahc" ) ;
break;
case IACT_API.IACT_HotelModifyGenAvail:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hamg" ) ;
break;
case IACT_API.IACT_HotelModifyDetAvail:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hamd" ) ;
break;
case IACT_API.IACT_HotelModifyHold:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hamh" ) ;
break;
case IACT_API.IACT_HotelFinancialAdjustment:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hafa" ) ;
break;
case IACT_API.IACT_HotelOptionChange:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","haoc" ) ;
break;
}
return url;
}
/**/ /// <summary>
/// 用于spoofer
/// </summary>
/// <param name="api"></param>
/// <param name="byPassSSL"></param>
/// <param name="soapMessage"></param>
/// <returns></returns>
private static string BuildURL ( IACT_API api , bool byPassSSL , string soapMessage)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml ( soapMessage );
string echoInfo = xmlDoc.SelectSingleNode ( "//EchoInfo" ).InnerText;
string url = "<protocol>//<server>/pub/agent.dll?qscr=<message>&tpid=<tpid>";
//获取server的ip
url = url.Replace ( "<server>",Config.SERVER );
//获取tpid
url = url.Replace ( "<tpid>",Config.TPID );
switch ( api )
{
case IACT_API.IACT_HotelGenAvail:
//url = url.Replace ( "<protocol>","http:");
//url = url.Replace ( "<message>","haga");
url = "He/GenAvail/GenAvail.aspx?case="+echoInfo;
break;
case IACT_API.IACT_HotelDetAvail:
url = url.Replace ( "<protocol>","http:" );
url = url.Replace ( "<message>" ,"hada" );
url = "http://****//DetAvail/DetAvail.aspx?case="+echoInfo;
break;
case IACT_API.IACT_Ping:
url = url.Replace ( "<protocol>","http:" );
url = url.Replace ( "<message>" ,"hapg" );
break;
case IACT_API.IACT_BookHold:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>","https:" );
url = url.Replace ( "<message>","habh" );
url = "http://****//BookHold/BookHold.aspx?case="+echoInfo;
break;
case IACT_API.IACT_BookCommit:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>","https:" );
url = url.Replace ( "<message>","habc" );
url = "http://****//Commit-Roll/Commit-Roll.aspx?case="+echoInfo;
break;
case IACT_API.IACT_BookRollback :
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","habr" ) ;
url = "http://****//Commit-Roll/Commit-Roll.aspx?case="+echoInfo;
break;
case IACT_API.IACT_HotelRateCalendar:
url = url.Replace ( "<protocol>","http:" );
url = url.Replace ( "<message>","harc" );
break;
case IACT_API.IACT_Retrieve:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hart" ) ;
url = "http://****//Retrieve/Retrieve.aspx?case="+echoInfo;
break;
case IACT_API.IACT_HotelCancel:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hahc" ) ;
url = "http://****//Cancel/Cancel.aspx?case="+echoInfo;
break;
case IACT_API.IACT_HotelModifyGenAvail:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hamg" ) ;
url = "http://****//ModifyGenAvail/ModifyGenAvail.aspx?case="+echoInfo;
break;
case IACT_API.IACT_HotelModifyDetAvail:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hamd" ) ;
url = "http://****//ModifyDetAvail/ModifyDetAvail.aspx?case="+echoInfo;
break;
case IACT_API.IACT_HotelModifyHold:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hamh" ) ;
url = "http://****//ModifyHold/ModifyHold.aspx?case="+echoInfo;
break;
case IACT_API.IACT_HotelFinancialAdjustment:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","hafa" ) ;
break;
case IACT_API.IACT_HotelOptionChange:
if ( byPassSSL )
{
url = url.Replace ( "<protocol>","http:" );
}
url = url.Replace ( "<protocol>" ,"https:" );
url = url.Replace ( "<message>","haoc" ) ;
url = "http://****//OptionChange/OptionChange.aspx?case="+echoInfo;
break;
}
return url;
}