We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

The remote server returned an error: (400) Bad Request.

MandiC77984
Regular Participant

The remote server returned an error: (400) Bad Request.

Here is my code ..I am getting issue get respoms

plz resolve my issue asap

 

string CCusername = "****";
string CCpassword = "****";
string CCuri = "https://api.constantcontact.com/ws/customers/" + CCusername + "/activities";

string CClistUri = "https://api.constantcontact.com/ws/customers/" + CCusername + "lists/1";
string CCAPIKEY = "******";

string Email = form["Email"].ToString();
string Name = form["Name"].ToString();

Uri address = new Uri(CCuri);
WebRequest request = WebRequest.Create(address);
request.Credentials = new NetworkCredential(CCAPIKEY + "%" + CCusername, CCpassword);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";

StringBuilder data = new StringBuilder();
data.Append("activityType=" + HttpUtility.UrlEncode("SV_ADD", Encoding.UTF8));
data.Append("&data=" + HttpUtility.UrlEncode(("Email Address,First Name" + "\n"), Encoding.UTF8));
data.Append(HttpUtility.UrlEncode((Email + "," + Name + ","), Encoding.UTF8));
data.Append("&lists=" + HttpUtility.UrlEncode(CClistUri));

Byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
String st = String.Empty;
request.ContentLength = byteData.Length;

Stream postStream = request.GetRequestStream();
using (postStream)
{
postStream.Write(byteData, 0, byteData.Length);
}

WebResponse response = request.GetResponse();

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

0 REPLIES 0
Developer Portal

View API documentation, code samples, get your API key.

Visit Page