私はVBを初めて使用しています...次のコードを使用してHTTPリクエストを作成し、レスポンスを文字列にバッファリングしています:
Try
myHttpWebRequest = CType(WebRequest.Create(strUrl), HttpWebRequest)
myHttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
receiveStream = myHttpWebResponse.GetResponseStream()
encode = System.Text.Encoding.GetEncoding("utf-8")
sr = New StreamReader(receiveStream, encode)
Do Until sr.Peek = -1
strLine = String.Concat(strLine, sr.ReadLine)
arrBuff.Add(strLine)
Loop
Catch ex As System.Net.WebException
MsgBox(ex.Message)
Finally
myHttpWebResponse.Close()
End Try
sr.Close()
これは正常に機能しますが、エラーは適切に処理されません。たとえば、要求が 500 応答をトリガーした場合、VB コードは未処理の例外に遭遇します。このコードを改善する方法について何か考えはありますか?