/*★ URL に接続して TEXT 形式で表示する 前田 稔 ★*/
#using <System.dll>
using namespace System;
using namespace System::Net;
using namespace System::IO;
using namespace System::Text;
int main( array< String^ >^ args )
{
Stream^ stream = nullptr;
StreamReader^ textReader = nullptr;
try
{
WebRequest^ req = HttpWebRequest::Create( L"http://www.yahoo.co.jp" );
WebResponse^ res = req->GetResponse();
stream = res->GetResponseStream();
//textReader = gcnew StreamReader( stream, Encoding::GetEncoding( L"euc-jp" ) );
//textReader = gcnew StreamReader( stream, Encoding::GetEncoding( L"Shift_JIS" ) );
//textReader = gcnew StreamReader( stream, Encoding::GetEncoding( 932 ) );
//textReader = gcnew StreamReader( stream, Encoding::GetEncoding( 0 ) );
//textReader = gcnew StreamReader( stream, Encoding::GetEncoding( L"Unicode" ) );
//textReader = gcnew StreamReader( stream, Encoding::GetEncoding( L"iso-2022-jp" ) );
textReader = gcnew StreamReader( stream, Encoding::GetEncoding( L"UTF-8" ) );
String^ line;
while ( line = textReader->ReadLine() )
{
Console::WriteLine( line );
}
}
catch ( Exception^ ex )
{
Console::WriteLine( ex->Message );
}
finally
{
if ( textReader != nullptr ) textReader->Close();
if ( stream != nullptr ) stream->Close();
}
Console::Read();
return 0;
}
|