2016-05-07 33 views
0

有https網站的api。Cordova(Phonegap)https的工作和調試

需要從cordova(angularjs)使用它的https API進行工作。

另外我想在webbrowser(chrome)中調試angularjs應用程序,因爲它非常快速(與重建和部署相比)。

簡單的代碼

$http({ 
    method: 'POST', 
    crossDomain: true, 
    xhrFields: { withCredentials: false }, 
    url: 'https://.../api/Auth', 
    data: { email: user, password: password } 
    }). 
    then(function (response) { 
     console.log("0", response); 
    }, function (response) { 
     console.log("1", response); 
    }); 

$.ajax({ 
    type: "POST", 
    url: 'https://.../api/Auth', 
    xhrFields: { 
     withCredentials: true 
    }, 
    crossDomain: true, 
    data: { email: user, password: password }, 
    success: function (response) { console.log("2", response) }, 
}); 
  1. 結果在科爾多瓦調試(Visual Studio中,Windows的x64)的

首先要求

HTTP500:服務器錯誤 - 服務器遇到了意外條件阻止它履行請求。 (XHR):GET - https://.../api/Auth?AspxAutoDetectCookieSupport=1

兩次,因爲$ HTTP + $就

第二和下一個請求 - 返回正確的響應(兩次太)

  • 結果在鉻
  • 所有請求

    一個)$ HTTP使用OPTION方法沒有POST

    B)$ http錯誤 的XMLHttpRequest不能加載https://.../api/Auth。預檢響應無效(重定向)

    C)$就使用正確POST

    d)$就錯誤 的XMLHttpRequest無法加載https://.../api/Auth。請求的資源上沒有「Access-Control-Allow-Origin」標題。因此不允許訪問原產地'http://local1.test'。

    問題

    1. 如何在科爾多瓦和鉻HTTPS使用相同的代碼工作的?

    2. 科爾多瓦如何正確跳過第一次請求並與第二次請求一起工作?

    +0

    您正在使用科爾多瓦和角,爲什麼不使用離子?在角度中的$ http'服務是一個ajax請求,所以使用它而不是'$ .ajax',因爲你使用的是角。此外它很高興與工廠提出請求以保持關注的分離 –

    +0

    感謝關於離子。我有角度的經驗。我需要簡單的應用。 $ .ajax是錯誤的示例。問題在https(CORPS)中。 –

    回答

    相關問題