开发者

remot server 403 error

hello i am working on asp.net and in that i want to add my contact list to constant contact website for that i have created trial account on constant contact. i used following code to add record to the constant contact database. but it show me following error

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

i got exception on response part

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)开发者_C百科, 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);

thank you in advance.


If you open the page in firefox and inspect the response in firebug you will see the second part of the error number. 403 is just the first part. It might be 403.1 or 403.9 or whatever. there are lots and the specific one will help you narrow down the cause. Also, try the same in HTTPWatch.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜