asp.net mvc 4 - An attempt to retrieve content from returned the HTTP status code 502. Please check the URL and try again -


when twilio trying access rest api url via post incoming sms seeing error.

 "an attempt retrieve content returned http status code 502. please check url , try again.   

what error , how fix it? error coming server or twilio side? missing on side? looking @ twilio web site given here:

http://www.twilio.com/docs/errors/11200

it says need set content-header. how do that? new web api , twiml.

edited:

this have under webapi.config

public static class webapiconfig {     public static void register(httpconfiguration config)     {         config.routes.maphttproute(             name: "defaultapi",             routetemplate: "{controller}/{id}",               defaults: new { id = routeparameter.optional }         );  

my route config has

public class routeconfig {     public static void registerroutes(routecollection routes)     {         routes.ignoreroute("{resource}.axd/{*pathinfo}");          routes.maproute(             name: "default",             url: "{controller}/{action}/{id}",              defaults: new { controller = "home", action = "index", id = urlparameter.optional }         );     } 

i added following in global.asax

    protected void application_start()     {         arearegistration.registerallareas();         webapiconfig.register(globalconfiguration.configuration);         filterconfig.registerglobalfilters(globalfilters.filters);         routeconfig.registerroutes(routetable.routes);         globalconfiguration.configuration.formatters.xmlformatter.adduripathextensionmapping("xml", "text/xml");         globalconfiguration.configuration.formatters.xmlformatter.adduripathextensionmapping("json", "application/json");          bundleconfig.registerbundles(bundletable.bundles);       } 

if add {action}.ext in webapi.config getting 404 error. did miss :-(

twilo evangelist here.

so web api determines how serialize data returned endpoint (json, xml, etc) looking @ accept header in incoming request. set content-type header based on format of data returns. problem twilio's web hook requests don't include accept header, , if there no accept header web api defaults returning json.

twilio expects twiml (our xml-based language) in response to request, if web api endpoint returning json twilio , setting content-type header in response application/json, twilio says thats bad.

there couple different ways can tell web api format response xml. first remove json formatter option available web api. post shows how remove json media type formatter collection of available formatters:

disable json support in asp.net mvc web api

another option tell web api use file extension way determine formatter use, instead of accept header using adduripathextensionmapping method:

globalconfiguration.configuration.formatters.xmlformatter.adduripathextensionmapping("xml", "text/xml"); 

that line tells web api treat request endpoints have .xml extension request text/xml media type response.

if this, have update web api route allow extension:

api/{controller}/{action}.{ext}/{id} 

hope helps.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -