Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Api post call works on postman but in mobile app or ajax call it doesn't

Api post call works on postman but in mobile app or ajax call it doesn't

Scheduled Pinned Locked Moved ASP.NET
helpjsoncsharpasp-netmobile
11 Posts 4 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M mrkeivan

    here's the problem I've got an API with the following address (HTTP post)

    http://api.novin.solutions/api/member/login
    "headers": {
    "accept": "application/json",
    "content-type": "application/x-www-form-urlencoded"
    },

      "data": {
        "username": "mrkeivan",
        "password": "09126101185",
        "uiId": "d960a994-0972-44ba-ae2c-2c3a01e135c1"
      }
    

    I need to call this api in another website and a mobile application, to do so I enabled Asp.net APi Cores globally in web config and WebApiConfig.cs **in WebApiConfig.cs** config.EnableCors(new EnableCorsAttribute("*", "*", "*")); > as well as Web.config

    when I call this in postman, it works perfectly however when I call it through an ajax method or a friend of mine calls it in his mobile app project it returns the following error > XMLHttpRequest cannot load > http://api.novin.solutions/api/member/login. Response for preflight > has invalid HTTP status code 404 OPTIONS > http://api.novin.solutions/api/member/login 404 (Not Found) I have read many articles in this matter and applied all the suggestions, but nothing fixed my problem :( any help would be appreciated

    F Offline
    F Offline
    F ES Sitecore
    wrote on last edited by
    #2

    When I made a call to that api this is the response I got

    HTTP/1.1 200 OK
    Cache-Control: no-cache, no-store
    Pragma: no-cache
    Content-Type: application/json; charset=utf-8
    Expires: -1
    Vary: Accept-Encoding
    Server: Microsoft-IIS/8.5
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Origin: *
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    X-Powered-By-Plesk: PleskWin
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Methods: POST, PUT, DELETE, GET, OPTIONS
    Access-Control-Allow-Headers: content-Type, accept, origin, X-Requested-With, Authorization, name
    Access-Control-Allow-Credentials: true
    Date: Thu, 09 Mar 2017 10:02:31 GMT
    Content-Length: 135

    Note that there are multiple "Access-Control-Allow-Origin" headers. The first thing I would do is look to why that is happening and get it down to one as the browser may well reject the response as invalid (if I use IE I get an error in the console explicitly stating there are duplicate headers). This is probably happening as you are configuring it in multiple places.

    M 1 Reply Last reply
    0
    • F F ES Sitecore

      When I made a call to that api this is the response I got

      HTTP/1.1 200 OK
      Cache-Control: no-cache, no-store
      Pragma: no-cache
      Content-Type: application/json; charset=utf-8
      Expires: -1
      Vary: Accept-Encoding
      Server: Microsoft-IIS/8.5
      Access-Control-Allow-Origin: *
      Access-Control-Allow-Origin: *
      X-AspNet-Version: 4.0.30319
      X-Powered-By: ASP.NET
      X-Powered-By-Plesk: PleskWin
      Access-Control-Allow-Origin: *
      Access-Control-Allow-Methods: POST, PUT, DELETE, GET, OPTIONS
      Access-Control-Allow-Headers: content-Type, accept, origin, X-Requested-With, Authorization, name
      Access-Control-Allow-Credentials: true
      Date: Thu, 09 Mar 2017 10:02:31 GMT
      Content-Length: 135

      Note that there are multiple "Access-Control-Allow-Origin" headers. The first thing I would do is look to why that is happening and get it down to one as the browser may well reject the response as invalid (if I use IE I get an error in the console explicitly stating there are duplicate headers). This is probably happening as you are configuring it in multiple places.

      M Offline
      M Offline
      mrkeivan
      wrote on last edited by
      #3

      Hi, thanx for the response removed them, now I only have it in - web.config and - config.EnableCors(); in WebApiConfig

      F 1 Reply Last reply
      0
      • M mrkeivan

        Hi, thanx for the response removed them, now I only have it in - web.config and - config.EnableCors(); in WebApiConfig

        F Offline
        F Offline
        F ES Sitecore
        wrote on last edited by
        #4

        Now there are two

        HTTP/1.1 200 OK
        Cache-Control: no-cache, no-store
        Pragma: no-cache
        Content-Type: application/json; charset=utf-8
        Expires: -1
        Vary: Accept-Encoding
        Server: Microsoft-IIS/8.5
        Access-Control-Allow-Origin: *
        Access-Control-Allow-Origin: *

        X-AspNet-Version: 4.0.30319
        X-Powered-By: ASP.NET
        X-Powered-By-Plesk: PleskWin
        Date: Thu, 09 Mar 2017 11:15:52 GMT
        Content-Length: 135

        You only need it defined once, but you are defining it in two config files

        M 2 Replies Last reply
        0
        • M mrkeivan

          here's the problem I've got an API with the following address (HTTP post)

          http://api.novin.solutions/api/member/login
          "headers": {
          "accept": "application/json",
          "content-type": "application/x-www-form-urlencoded"
          },

            "data": {
              "username": "mrkeivan",
              "password": "09126101185",
              "uiId": "d960a994-0972-44ba-ae2c-2c3a01e135c1"
            }
          

          I need to call this api in another website and a mobile application, to do so I enabled Asp.net APi Cores globally in web config and WebApiConfig.cs **in WebApiConfig.cs** config.EnableCors(new EnableCorsAttribute("*", "*", "*")); > as well as Web.config

          when I call this in postman, it works perfectly however when I call it through an ajax method or a friend of mine calls it in his mobile app project it returns the following error > XMLHttpRequest cannot load > http://api.novin.solutions/api/member/login. Response for preflight > has invalid HTTP status code 404 OPTIONS > http://api.novin.solutions/api/member/login 404 (Not Found) I have read many articles in this matter and applied all the suggestions, but nothing fixed my problem :( any help would be appreciated

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #5

          If that's your real password that you've just posted on a public forum, I hope it doesn't provide access to any sensitive data, and that you're going to change it as soon as the problem is resolved. :)


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          M 1 Reply Last reply
          0
          • F F ES Sitecore

            Now there are two

            HTTP/1.1 200 OK
            Cache-Control: no-cache, no-store
            Pragma: no-cache
            Content-Type: application/json; charset=utf-8
            Expires: -1
            Vary: Accept-Encoding
            Server: Microsoft-IIS/8.5
            Access-Control-Allow-Origin: *
            Access-Control-Allow-Origin: *

            X-AspNet-Version: 4.0.30319
            X-Powered-By: ASP.NET
            X-Powered-By-Plesk: PleskWin
            Date: Thu, 09 Mar 2017 11:15:52 GMT
            Content-Length: 135

            You only need it defined once, but you are defining it in two config files

            M Offline
            M Offline
            mrkeivan
            wrote on last edited by
            #6

            How do you make this call ???

            F 1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              If that's your real password that you've just posted on a public forum, I hope it doesn't provide access to any sensitive data, and that you're going to change it as soon as the problem is resolved. :)


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              M Offline
              M Offline
              mrkeivan
              wrote on last edited by
              #7

              :)))) don't worry it's a sample ! :laugh:

              1 Reply Last reply
              0
              • F F ES Sitecore

                Now there are two

                HTTP/1.1 200 OK
                Cache-Control: no-cache, no-store
                Pragma: no-cache
                Content-Type: application/json; charset=utf-8
                Expires: -1
                Vary: Accept-Encoding
                Server: Microsoft-IIS/8.5
                Access-Control-Allow-Origin: *
                Access-Control-Allow-Origin: *

                X-AspNet-Version: 4.0.30319
                X-Powered-By: ASP.NET
                X-Powered-By-Plesk: PleskWin
                Date: Thu, 09 Mar 2017 11:15:52 GMT
                Content-Length: 135

                You only need it defined once, but you are defining it in two config files

                M Offline
                M Offline
                mrkeivan
                wrote on last edited by
                #8

                this is what I get Request Accept:*/* Accept-Encoding:gzip, deflate, sdch Accept-Language:en-US,en;q=0.8 Access-Control-Request-Headers:cache-control Access-Control-Request-Method:POST Cache-Control:no-cache Connection:keep-alive Host:api.novin.solutions Origin:http://localhost:1344 Pragma:no-cache Referer:http://localhost:1344/Home/Index User-Agent:Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 Response Access-Control-Allow-Credentials:true Access-Control-Allow-Headers:content-Type, accept, origin, X-Requested-With, Authorization, name Access-Control-Allow-Methods:POST, PUT, DELETE, GET, OPTIONS Access-Control-Allow-Origin:* Connection:close Content-Length:1245 Content-Type:text/html Date:Fri, 10 Mar 2017 05:26:20 GMT Server:Microsoft-IIS/8.5 Vary:Accept-Encoding X-Powered-By:ASP.NET X-Powered-By-Plesk:PleskWin

                1 Reply Last reply
                0
                • M mrkeivan

                  How do you make this call ???

                  F Offline
                  F Offline
                  F ES Sitecore
                  wrote on last edited by
                  #9

                  Via ajax and I use Fiddler to examine the response

                  $(document).ready(function () {
                  $.ajax({
                  type: "POST",
                  url: "http://api.novin.solutions/api/member/login",
                  data: {
                  "username": "mrkeivan",
                  "password": "09126101185",
                  "uiId": "d960a994-0972-44ba-ae2c-2c3a01e135c1"
                  }
                  }).done(function (data) {
                  alert(data);
                  }).fail(function (jqXHR, textStatus) {
                  alert("Request failed: " + textStatus);
                  });
                  });

                  M 1 Reply Last reply
                  0
                  • F F ES Sitecore

                    Via ajax and I use Fiddler to examine the response

                    $(document).ready(function () {
                    $.ajax({
                    type: "POST",
                    url: "http://api.novin.solutions/api/member/login",
                    data: {
                    "username": "mrkeivan",
                    "password": "09126101185",
                    "uiId": "d960a994-0972-44ba-ae2c-2c3a01e135c1"
                    }
                    }).done(function (data) {
                    alert(data);
                    }).fail(function (jqXHR, textStatus) {
                    alert("Request failed: " + textStatus);
                    });
                    });

                    M Offline
                    M Offline
                    mrkeivan
                    wrote on last edited by
                    #10

                    you are right, i found out a line I left in the global.cs :^) :^) :^) :^) thanx man, appreciate it.

                    1 Reply Last reply
                    0
                    • M mrkeivan

                      here's the problem I've got an API with the following address (HTTP post)

                      http://api.novin.solutions/api/member/login
                      "headers": {
                      "accept": "application/json",
                      "content-type": "application/x-www-form-urlencoded"
                      },

                        "data": {
                          "username": "mrkeivan",
                          "password": "09126101185",
                          "uiId": "d960a994-0972-44ba-ae2c-2c3a01e135c1"
                        }
                      

                      I need to call this api in another website and a mobile application, to do so I enabled Asp.net APi Cores globally in web config and WebApiConfig.cs **in WebApiConfig.cs** config.EnableCors(new EnableCorsAttribute("*", "*", "*")); > as well as Web.config

                      when I call this in postman, it works perfectly however when I call it through an ajax method or a friend of mine calls it in his mobile app project it returns the following error > XMLHttpRequest cannot load > http://api.novin.solutions/api/member/login. Response for preflight > has invalid HTTP status code 404 OPTIONS > http://api.novin.solutions/api/member/login 404 (Not Found) I have read many articles in this matter and applied all the suggestions, but nothing fixed my problem :( any help would be appreciated

                      A Offline
                      A Offline
                      acentriatech
                      wrote on last edited by
                      #11

                      If that's your real password that you've just posted on a public forum, I hope it doesn't provide access to any sensitive data, and that you're going to change it as soon as the problem is resolved. Smile | :)

                      Best Web development Company.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups