Httpreqest
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时解压
未压缩时
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时解压
未压缩时
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;
}