Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
禁止:403使用wcf restful服务时出错_Wcf_Http Status Code 403_Wcf Rest - Fatal编程技术网

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

禁止:403使用wcf restful服务时出错,wcf,http-status-code-403,wcf-rest,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);

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

我不明白为什么它失败了。你知道吗?

你一直在请求同一个URI(当你收到错误时)。您能否尝试捕获异常并检查是否存在任何子状态(例如403.14,目录列表被拒绝)?我认为你需要收集更多的信息来解决这个问题。回复文本说,“底层连接已关闭”,那么托管服务呢?你能控制它吗?它在哪里托管?凭什么?