wcf restful サービスを利用しようとしています。コードは次のとおりです。
private static string SendRequest(string uri, string method, string contentType, string body)
{
string responseBody = null;
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri);
req.Method = method;
if (!String.IsNullOrEmpty(contentType))
{
req.ContentType = contentType;
}
if (body != null)
{
byte[] bodyBytes = Encoding.UTF8.GetBytes(body);
req.GetRequestStream().Write(bodyBytes, 0, bodyBytes.Length);
req.GetRequestStream().Close();
}
req.Accept = "*/*";
HttpWebResponse resp;
resp = (HttpWebResponse)req.GetResponse();
return responseBody;
}
今の問題は、時々うまく動作し、時にはエラーが発生することです
"the remote server returned an error 403 forbidden."
なぜ失敗するのかわかりません。何か案が???