禁止:使用wcf restful服务时403错误

时间:2011-03-11 17:14:17

标签: wcf http-status-code-403 wcf-rest

我正在尝试使用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."

我无法弄清楚它失败的原因。任何想法???

0 个答案:

没有答案