65,210
社区成员
发帖
与我相关
我的任务
分享#include <string>
#include <boost/regex.hpp>
#include <boost/lambda/lambda.hpp>
using namespace std;
using namespace boost;
#pragma warning (disable : 4290)
void GetHostNameFromRequest(const string& HttpHead,string& hostname) throw (string)
{
boost::regex rHostname("(?<=Host: )[\\s\\S]*?(?=\r\n)");
std::string::const_iterator begin,end;
smatch sm;
hostname.clear();
begin=HttpHead.begin();
end=HttpHead.end();
regex_search(begin,end,sm,rHostname);
hostname=sm[0];
if(hostname.size()<=0)
{
cout<<&HttpHead<<endl;
throw HttpHead;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
try
{
string a;
GetHostNameFromRequest("dd",a);
}
catch(string b)
{
cout<<&b<<endl;
}
cout<<"done"<<endl;
system("pause");
return 0;
}