コメント |
@DIV
Module MyModule
' ********************************************************
'
' ********************************************************
Sub Main()
@C:green(' HttpWebRequest のインスタンス
' コンストラクタでは無く、Create メソッドを使用する)
Dim req As System.Net.HttpWebRequest = _
System.Net.HttpWebRequest.Create("http://localhost/web/test/sv1.php")
req.Method = "GET"
@C:green(' HttpWebResponse のインスタンスを取得[ 送信 ])
Dim res As System.Net.HttpWebResponse = req.GetResponse()
@C:green(' Stream)
Dim resStream As System.IO.Stream = res.GetResponseStream()
@C:green(' 全て表示)
Dim sr As New System.IO.StreamReader(resStream)
Console.WriteLine( sr.ReadToEnd() )
@C:green(' Streamを閉じる)
sr.Close()
@C:green(' ヘッダー情報の取得)
Dim str As String
Dim str2 As String()
Dim strValue As String
@C:green(' 次の HttpWebRequestを作成)
req = System.Net.HttpWebRequest.Create("http://localhost/web/test/sv2.php")
@C:green(' Set-Cookie を Cookie で送り返す)
For Each str In res.Headers
str2 = res.Headers.GetValues(str)
For Each strValue In str2
Console.WriteLine(str + ": " + strValue )
Next
if str = "Set-Cookie" then
strValue = res.Headers.Get(str)
strValue = strValue.Replace(",", "; ")
req.Headers.Add("Cookie", strValue )
end if
Next
@C:green(' 送信)
res = req.GetResponse()
@C:green(' 受信と表示)
resStream = res.GetResponseStream()
sr = New System.IO.StreamReader(resStream)
Console.WriteLine(sr.ReadToEnd())
sr.Close()
End Sub
End Module
@END |