开发者

forbidden:403 error while using wcf restful service

I am trying to consume wcf restful service. The code is as follows:

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.IsNullOrEm开发者_高级运维pty(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;
        }

Now the issue is, sometimes it works fine and sometimes i get the error

"the remote server returned an error 403 forbidden."

I cannot figure out why it fails. Any idea???

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜