简体   繁体   English

cordova项目给出了unsupported_grant_type错误,但在浏览器上也可以使用

[英]cordova project gives unsupported_grant_type error but same works on browser

I have a ASP.Net WebAPI2 website that has a /token implementing the OWIN token service. 我有一个ASP.Net WebAPI2网站,该网站具有实现OWIN令牌服务的/ token。 This service is working just fine for my website, I am able to use rest clients and get the token as expected both from my PC as well as Android Phone. 这项服务在我的网站上正常工作,我可以使用其余客户端,并从PC和Android Phone上按预期方式获得令牌。

however when I call the service from inside my ionic project deployed on my android phone KitKat OS, i get {"error":"unsupported_grant_type"} . 但是,当我从部署在Android手机KitKat OS上的离子项目内部调用服务时,我得到{"error":"unsupported_grant_type"} Its on the same wifi so I am able to use a rest client and get the token using that. 它在同一个wifi上,因此我可以使用rest客户端并使用该客户端获取令牌。

here is the angular code that I am using: 这是我正在使用的角度代码:

.service('LoginTokenService', ['$resource', function ($resource) {
    function getToken(payLoad, fnSuccess, fnError) {
        return $resource("http://192.168.1.104/token", {},
      {
          "getAuthToken": {
              method: "POST",
              isArray: false,
              headers: { 'Content-Type': 'application/x-www-form-urlencoded' },

          }
      })
    .getAuthToken(payLoad, fnSuccess, fnError);
    }
    return ({
        getToken: getToken
    });

Also on my webapi code I have set the option app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); 同样在我的webapi代码上,我设置了选项app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); like below 像下面

    public void ConfigureAuth(IAppBuilder app)
    {

        app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

        // Mounts the middleware on the provided app with the options configured
        // above
        app.UseOAuthBearerTokens(OAuthOptions);
    }

Also the payLoad contains UserName='myuser@domain.com', Password='my_password' & grant_type='password' 此外, payLoad包含UserName='myuser@domain.com', Password='my_password' & grant_type='password'

as I am relatively new to ionic and cardova I was wondering if anyone has encountered the similar issue. 因为我对Ionic和Cardova还是比较陌生,所以我想知道是否有人遇到过类似的问题。

I think I know the issue. 我想我知道这个问题。 on my Website, i used $.param(payload) to send login info to the /token service, but as JQuery was not available in the ionic by default, I removed that. 在我的网站上,我使用$.param(payload)将登录信息发送到/ token服务,但是由于默认情况下Iionic无法使用JQuery,因此我将其删除了。

I have now used the $httpParamSerializerJQLike(payLoad) to serialize the payload and its working now.. 我现在使用$httpParamSerializerJQLike(payLoad)来序列化有效负载及其工作状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 {“ error”:“ unsupported_grant_type”}进行语音通话 - {“error”:“unsupported_grant_type”} for angular call 使用angularjs将json发送到spring控制器时,浏览器控制台中出现不受支持的媒体类型错误 - Unsupported Media Type error in browser console when sending json using angularjs to spring controller Cordova Inapp浏览器抛出错误 - Cordova Inapp browser throws error 建立Cordova项目时出错 - Error while building cordova project HTTP状态415 –不支持的媒体类型错误 - HTTP Status 415 – Unsupported Media Type error AngularJS 和 Cordova $http 问题 - 浏览器工作正常,应用程序不工作 - AngularJS & Cordova $http issues - browser works fine, app does not 必需参数缺少grant_type Google oauth2.0 AngularJS和Cordova inappbrowser - Required Parameter is missing grant_type Google oauth2.0 AngularJS and Cordova inappbrowser 组件的angular 2导入在VS中有效,但在浏览器中给出404 - angular 2 import of component works in VS, but gives 404 in browser AngularFire浏览器刷新给出错误页面未找到 - AngularFire browser Refresh gives error page not Found 415-不支持的媒体类型错误| angularjs + Spring3.2 - 415- Unsupported Media Type Error | angularjs + Spring3.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM