Reply
Contributing Developer
DonorManagement
Posts: 19
Registered: ‎01-20-2009

Re: Error media not supported

Dave,

 

I made the change top the request.contenttype and now I receive the error: :The remote server returned an error: (400) Bad Request. "

DaveBerard
Posts: 1,635
Topics: 7
Kudos: 61
Solutions: 58
Registered: ‎06-19-2008

Re: Error media not supported

You should be able to use code similar to this to read the full response to that error.  It will tell you what the cause of the 400 is, which indicates that some of the XML content you sent was not valid.  If you can get the full response, we can help direct you to fixing the XML.

 

Using ex.response As HttpWebResponse = TryCast(request.GetResponse(), HttpWebResponse)
Dim reader As New StreamReader(response.GetResponseStream())
String st = reader.ReadToEnd()
Dave Berard
Senior Product Manager, Constant Contact
Contributing Developer
DonorManagement
Posts: 19
Registered: ‎01-20-2009

Re: Error media not supported

[ Edited ]

Dave,

 

Because of the error we are not having any luck in getting the full response back as you suggested. If the xml is being sent as it is in your example. do you know for sure that that example xml is valid? Or maybe you know how we can modify our response code to to return the full response or another way to see the full response.

 

In any case we appreciate any suggestions you can offer.

DaveBerard
Posts: 1,635
Topics: 7
Kudos: 61
Solutions: 58
Registered: ‎06-19-2008

Re: Error media not supported

The code I mentioned must be put in the catch block.  That way, once the HttpWebRequest throws the exception, you can get the full response through the exception being thrown. 

 

I think it may be my fault for not noticing this earlier, but the correct way to catch this code is with a webexception, not a standard exception.  You would want to change your catch to:

 

catch ex as WebException

 

The WebException has the full response messages as well and then the code I posted will work in the catch handling code.

Dave Berard
Senior Product Manager, Constant Contact
Contributing Developer
DonorManagement
Posts: 19
Registered: ‎01-20-2009

Re: Error media not supported

Dave,

 

The webException returned the following:

 

System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.GetResponse() at
Constant_Contact.AddNewContactList(String sListName)

 

It indicated line 337 which is:

         

Using response AsHttpWebResponse = TryCast(request.GetResponse(), HttpWebResponse)


DaveBerard
Posts: 1,635
Topics: 7
Kudos: 61
Solutions: 58
Registered: ‎06-19-2008

Re: Error media not supported

Please try the following code sample, this should correctly give you the full error message being returned by us:

 

catch ex as WebException

    Using ex.response As HttpWebResponse = TryCast(request.GetResponse(), HttpWebResponse)
    Dim reader As New StreamReader(response.GetResponseStream())
    String st = reader.ReadToEnd()

    HttpContext.Current.Response.Write(st)

end try

Dave Berard
Senior Product Manager, Constant Contact
Contributing Developer
DonorManagement
Posts: 19
Registered: ‎01-20-2009

Re: Error media not supported

Dave,

 

I have been able to gleen this from IE, does it help you help us?

 

Invalid at the top level of the document.
Line: 1 Character: 1

Error 400: The request contains errors in the common Atom sections, which lie outside <entry> or <Content>, such as <feed>, <id>, <author> or <updated>.

DaveBerard
Posts: 1,635
Topics: 7
Kudos: 61
Solutions: 58
Registered: ‎06-19-2008

Re: Error media not supported

The XML created from that code works for me in my test applications, the error we're receiving says that there is a problem with the content.  I didn't believe that this would cause an issue, but it could be the encoding method you are using.  Both my sample applicatoins and our .NET sample code uses the following encoding option:

 

Encoding.ASCII.GetBytes()

 

This would encode it correctly in ASCII encoding, which is the only character encoding set we currently support.  If any of the characters you encoded to UTF8 ended up being multi-byte characters, it would correctly cause a 400 error to be returned.

Dave Berard
Senior Product Manager, Constant Contact
Contributing Developer
DonorManagement
Posts: 19
Registered: ‎01-20-2009

Re: Error media not supported

Dave,

 

Can you pass me the C# code from your sample app that works? At worst I could try and convert it and tesat it hear.

 

Much appreciated.

Contributing Developer
DonorManagement
Posts: 19
Registered: ‎01-20-2009

Re: Error media not supported

Dave,

 

I changed to the ASCII encoding and I get the exact same error as I previously posted from IE.

 

This may be a silly question,but are we using the correct URI for this type of request?

 

https://api.constantcontact.com/ws/customers/" & ctu & "/activities"