サーバーからの応答に関して問題があります。(403 禁止を返します)。
ブラウザで同じURLをチェックしていると、ページが表示されます。
応答を取得するための以下のコードを作成しました。
同じコードをローカル PC で実行しています。正常に動作します。
HttpWebRequest request = WebRequest.Create(RequestUrl) as HttpWebRequest;
request.Method = "POST";
request.CookieContainer = new CookieContainer();
request.Timeout = 600000;
request.Accept = "*/*";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:18.0) Gecko/20100101 Firefox/18.0";
WebResponse response;
try
{
response = request.GetResponse();
string StatusDescription = ((HttpWebResponse)response).StatusDescription;
if (StatusDescription.ToLower() == "ok")
{
Stream dataStream = response.GetResponseStream();
//XmlDocument XmlResponse = new XmlDocument();
//XmlResponse.Load(dataStream);
//XmlResponse.Save(Server.MapPath("~/XMLResponse.xml"));
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
responseFromServer = responseFromServer.Replace(" ", "");
responseFromServer = responseFromServer.Replace("&", "&");
reader.Close();
dataStream.Dispose();
response.Close();
responseFromServer = GetStringsBetweenTags(responseFromServer, "<head>", "</head>");
return responseFromServer;
}
else
{
//To Do : add code for notify error via email
}
}
catch (Exception ex)
{
WebClient webclient = new WebClient();
using (StreamReader reader = new StreamReader(webclient.OpenRead(RequestUrl)))
{
string responseFromServer = reader.ReadToEnd();
responseFromServer = responseFromServer.Replace(" ", "");
responseFromServer = responseFromServer.Replace("&", "&");
reader.Close();
webclient.Dispose();
responseFromServer = GetStringsBetweenTags(responseFromServer, "<head>", "</head>");
return responseFromServer;
}
}