得到错误“远程服务器返回错误:(403)禁止。”在(HttpWebResponse)request.GetResponse()中

时间:2019-07-18 11:36:02

标签: c# rest model-view-controller httpwebrequest httpwebresponse

远程服务器返回错误:(403)禁止。但在本地计算机上运行正常。当我在服务器上发布时,它给我错误。

我在Google上搜索并尝试了与此相关的一些解决方案。但对我没有帮助。

请参见下面的代码,并提出解决该问题的建议方案。

我从下面的链接尝试了一些解决方案。

HttpWebResponse return The remote server returned an error: (403) Forbidden

The remote server returned an error: (403) Forbidden in C#

VB.Net - The remote server returned an error: (403) Forbidden

try
                                {
                                    var stringImage = Encoding.UTF8.GetBytes(_UploadFileCollection.UploadFileData[i].stringFile);
                                    string tmpRequestDetailsID = _RefundAmountDetails.RequestDetailsID.ToString();
                                    string refNo_RequestID = tmpRequestDetailsID;
                                    string docN_FileName = _UploadFileCollection.UploadFileData[i].FileName;
                                    HttpWebRequest Chequerequest = WebRequest.Create(DMSURL) as HttpWebRequest;
                                    Newtonsoft.Json.Linq.JArray _binData = new Newtonsoft.Json.Linq.JArray(from c in stringImage select new Newtonsoft.Json.Linq.JValue(c));
                                    Newtonsoft.Json.Linq.JObject json = Newtonsoft.Json.Linq.JObject.FromObject(new
                                    {
                                        dept = "IT",
                                        author = "supervisor",
                                        app = "FastTrack",
                                        ent = "",
                                        refTyp = "REFUND",
                                        refNo = refNo_RequestID,
                                        docTyp = "Cheque",
                                        docN = docN_FileName,
                                        fileTyp = "I",
                                        binData = _binData
                                    });
                                    string chequesb = JsonConvert.SerializeObject(json);
                                    Chequerequest.Method = "POST";
                                    Chequerequest.ContentType = "application/json";
                                    Byte[] bt = Encoding.UTF8.GetBytes(chequesb);
                                    Stream chequest = Chequerequest.GetRequestStream();
                                    chequest.Write(bt, 0, bt.Length);
                                    chequest.Close();
                                    using (HttpWebResponse Chequeresponse = Chequerequest.GetResponse() as HttpWebResponse)
                                    {
                                        if (Chequeresponse.StatusCode != HttpStatusCode.OK) throw new Exception(String.Format(
                                            "Server error (HTTP {0}: {1}).", Chequeresponse.StatusCode,
                                        Chequeresponse.StatusDescription));
                                        Stream Chequestream = Chequeresponse.GetResponseStream();
                                        StreamReader chequesr = new StreamReader(Chequestream);
                                        string strsbCheque = chequesr.ReadToEnd();
                                        // Response.Write(strsb);
                                        DMSResponse objImageResponse = JsonConvert.DeserializeObject<DMSResponse>(strsbCheque);
                                        int docID = objImageResponse.docId;
                                        chequeDocID = docID.ToString();


                                    }

                                    if (!string.IsNullOrEmpty(chequeDocID))
                                    {

                                        DocumentUpload = "Success";
                                        UploadFileData _objUploadFileData = new UploadFileData();
                                        _objUploadFileData.DocID = chequeDocID;
                                        _objUploadFileData.DocType = "Cheque";
                                        _objUploadFileDataList.Add(_objUploadFileData);
                                    }
                                    else
                                    {
                                        DocumentUpload = "Document Upload Faield";
                                    }

                                }
                                catch (Exception ex)
                                {
                                    CommonUtility.WriteLog("InsertBankDetails Cheque : " + ex.Message + "-" + DateTime.Now.ToString());
                                    DocumentUpload = "Document Upload Faield" + ex.Message;
                            }

我希望得到服务的结果。但这给了我错误。

0 个答案:

没有答案