1

我正在尝试使用 wcf 宁静的服务。代码如下:

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."

我无法弄清楚它为什么会失败。任何想法???

4

0 回答 0