HttpListenerを - どのように私はブラウザにWebException HTTP 304「修正しない」エラーバックを送っていますか?
-
25-09-2019 - |
質問
私が使用している場合、私はブラウザにWebException 304エラーバックを模倣するにはどうすればよいHttpListenerを?
私はHttpListenerをへの要求を受け、その後、HttpListenerContextを取得しているされていること、そして、この時点から、どのように私は模倣/効果的HttpListenerContext経由でブラウザに背中を送信するHTTP「304変更されていない」応答を手配します。応答?
EDITます:
私は、しかし、私は(ステータスコードは正確に3桁の数字でなければなりません)HttpWebResponse.StatusCodeにWebException.Statusをコピーしようとしているエラーを取得するには、次を試してみました。これを修正する方法上の任意のアイデア?
catch (WebException ex)
{
listenerContext.Response.StatusCode = (int)ex.Status; //ERROR: The status code must be exactly three digits
listenerContext.Response.StatusDescription = ex.Message;
listenerContext.Response.Close();
感謝
解決
私は私がそれを持っていると思います。
catch (WebException ex)
{
if (ex.Status == WebExceptionStatus.ProtocolError)
{
int statusCode = (int) ((HttpWebResponse) ex.Response).StatusCode;
listenerContext.Response.StatusCode = statusCode;
listenerContext.Response.StatusDescription = ex.Message;
log("WARNING", uri, "WebException/ProtocolError: " + ex.GetType() + " - " + ex.Message);
}
else
{
log("ERROR", uri, "WebException - " + ex.GetType() + " - " + ex.Message);
}
listenerContext.Response.Close();
}
所属していません StackOverflow