質問

I am creating browser extension using crossrider. After installation of this extension is comlete, it need's to call wcf service, it is working fine in chrome, firefox and safari but in IE it is showing badrequest error i.e, Error 400. The following is my Crossrider Code

 appAPI.request.post({
    url: 'http://183.82.102.245:8020/Service1.svc/json/GetAffiliatedUrlsCollection',
    onSuccess: function(response) {var site = appAPI.JSON.parse(response);
    AddUrlsToDB(site);
    },        
    onFailure: function(httpCode) {
        alert('Failed to retrieve content. (HTTP Code:' + httpCode + ')');
    },
    additionalRequestHeaders: {
        myHeader: 'value'
    },
    contentType: 'application/json'
});

the following is my service code

 [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "GetAffiliatedUrlsCollection", BodyStyle =     WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
    List<UrlInfo> GetAffiliatedUrlsCollection();

The following is my properties

 [DataContract]
public class UrlInfo
{
    private string affiliatedurl; 
    public string websiteurl;
    public bool autoapprove;

    public UrlInfo(string websiteurl, string affiliatedurl, bool autoapprove)
    {
        this.websiteurl = websiteurl;
        this.affiliatedurl = affiliatedurl;
        this.autoapprove = autoapprove;
    }

    [DataMember]
    public string WebsiteUrl
    {
        get { return websiteurl; }
        set { websiteurl = value; }
    }

    [DataMember]
    public string AffilateUrl
    {
        get { return affiliatedurl; }
        set { affiliatedurl = value; }
    }

    [DataMember]
    public bool AutoApprove
    {
        get { return autoapprove; }
        set { autoapprove = value; }
    }
}

Then Globla.asax

protected void Application_BeginRequest(object sender, EventArgs e)
    {
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
        if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
        {
            HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET,     POST");
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, x-requested-with");
            HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
            HttpContext.Current.Response.End();
        }
    }
役に立ちましたか?

解決

I tested the following code on Win7/IE10 and the response was received as expected. Did you make any changes to your server? Are you still experiencing a problem?

appAPI.request.post({
    url: 'http://183.82.102.245:8020/Service1.svc/json/GetAffiliatedUrlsCollection',
    onSuccess: function(response) {
        alert(response);
    },        
    onFailure: function(httpCode) {
        alert('Failed to retrieve content. (HTTP Code:' + httpCode + ')');
    },
    contentType: 'application/json; charset=UTF-8; charset-uf8'
});

[Disclosure: I am a Crossrider employee]

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top