远程服务器403错误

时间:2010-07-28 13:18:04

标签: asp.net

您好我正在使用asp.net,并且我希望将我的联系人列表添加到常规联系网站,因为我已经创建了常规联系的试用帐户。我使用以下代码将记录添加到常量联系人数据库。但它显示我跟随错误

远程服务器返回错误:(403)Forbidden。

我在回复部分

上有例外
Uri address=new Uri(sUri);
         HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

         request.Credentials=new NetworkCredential ((sAPIKey + "%" + sUsername), sPassword);
         request.Method = "POST";
         request.ContentType = "application/x-www-form-urlencoded";

        //Build data string

        var data=new StringBuilder();
        data.Append("activityType=" + HttpUtility.UrlEncode("ADD_CONTACTS", Encoding.UTF8));

        data.Append("&data=" + HttpUtility.UrlEncode(("Email Address,Email Type,First Name,Last Name" + Convert.ToChar(10)), Encoding.UTF8));
        data.Append(HttpUtility.UrlEncode((email.Text + ",HTML," + txtfname.Text + "," + txtlname.Text), Encoding.UTF8));
        data.Append("&lists=" + HttpUtility.UrlEncode(sListUri));

        byte[]  byteData  = UTF8Encoding.UTF8.GetBytes(data.ToString());
        string st  = string.Empty;

       request.ContentLength = byteData.Length;
       using (Stream  postStream  = request.GetRequestStream())
         {

        postStream.Write(byteData, 0, byteData.Length);
         }


       using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
       {
           StreamReader reader = new StreamReader(response.GetResponseStream());
           st = reader.ReadToEnd();
       } 




    string sCode =Convert.ToString( Response.StatusCode);

提前谢谢。

1 个答案:

答案 0 :(得分:0)

如果您在firefox中打开页面并检查firebug中的响应,您将看到错误编号的第二部分。 403只是第一部分。它可能是403.1或403.9或其他什么。有很多,具体的将帮助你缩小原因。另外,在HTTPWatch中尝试相同的操作。