英文:
IONIC - cordova-plugin-advanced-http post call fails with Cookie Error
问题
在使用Android SDK 32进行POST调用时,遇到以下错误:
{"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":-1,"statusText":"Unknown Error","url":"https://ddomain.com/loginUsingApim","ok":false,"name":"HttpErrorResponse","message":"Http failure response for https://ddomain.com/loginUsingApim: -1 undefined","error":"Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference"}
在日志中看到以下错误:
发生了意外错误
java.lang.NullPointerException: 尝试在空对象引用上调用虚拟方法 'java.lang.Class
java.lang.Object.getClass()'
at cy0.<init>(chromium-TrichromeWebViewGoogle.aab-stable-556311633:4)
在com.android.webview.chromium.a.setCookie(chromium-TrichromeWebViewGoogle.aab-stable-556311633:4)
在com.getcapacitor.plugin.CapacitorCookieManager.setCookie(CapacitorCookieManager.java:123)
在com.getcapacitor.plugin.CapacitorCookieManager.put(CapacitorCookieManager.java:176)
在com.android.okhttp.internal.http.HttpEngine.receiveHeaders(HttpEngine.java:891)在com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:625)
在com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:475)
在com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
在com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:542)
在com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:106)
在com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:30)
在com.silkimen.http.HttpRequest.code(HttpRequest.java:1447)
在com.silkimen.http.HttpRequest.stream(HttpRequest.java:1740)
在com.silkimen.http.HttpRequest.buffer(HttpRequest.java:1729)
在com.silkimen.http.HttpRequest.receive(HttpRequest.java:1856)
在com.silkimen.cordovahttp.CordovaHttpBase.processResponse(CordovaHttpBase.java:195)
在com.silkimen.cordovahttp.CordovaHttpBase.run(CordovaHttpBase.java:81)
在java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:463)
在java.util.concurrent.FutureTask.run(FutureTask.java:264)
在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
在java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
在java.lang.Thread.run(Thread.java:1012)
我的Package.json文件包含:
"@angular/common": "^14.2.12",
"@angular/core": "^14.2.12",
"@angular/forms": "^14.2.12",
"@angular/platform-browser": "^14.2.12",
"@angular/platform-browser-dynamic": "^14.2.12",
"@angular/router": "^14.2.12",
"@awesome-cordova-plugins/core": "^5.40.0",
"@awesome-cordova-plugins/email-composer": "^5.40.0",
"@awesome-cordova-plugins/screen-orientation": "^5.41.0",
"@awesome-cordova-plugins/social-sharing": "^5.40.0",
"@capacitor/android": "4.7.3",
"@capacitor/app": "^4.0.0",
"@capacitor/core": "^4.0.0",
"@capacitor/haptics": "^4.0.0",
"@capacitor/ios": "^4.0.0",
"@capacitor/keyboard": "^4.0.0",
"@capacitor/preferences": "^4.0.0",
"@ionic-native/app-availability": "^5.31.0",
"@ionic-native/app-version": "^5.36.0",
"@ionic-native/core": "^5.33.1",
"@ionic-native/file": "^5.31.1",
"@ionic-native/http": "^5.34.0",
"@ionic-native/in-app-browser": "^5.36.0",
"@ionic-native/ionic-webview": "^5.36.0",
"@ionic-native/local-notifications": "^5.36.0",
"@ionic-native/network": "^5.33.1",
"@ionic-native/pdf-generator": "^5.34.0",
"@ionic-native/social-sharing": "^5.36.0",
"@ionic-native/sqlite": "^5.33.1",
"@ionic-native/sqlite-porter": "^5.33.1",
"@ionic-native/web-intent": "^5.36.0",
"@ionic-native/zip": "^5.36.0",
"@ionic/angular": "^6.3.8",
"@ionic/storage": "^3.0.6",
"@ionic/storage-angular": "^3.0.6",
"@obsidize/
<details>
<summary>英文:</summary>
While making a post call from android sdk 32, getting the below error :-
```{"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":-1,"statusText":"Unknown Error","url":"https://ddomain.com/loginUsingApim","ok":false,"name":"HttpErrorResponse","message":"Http failure response for https://ddomain.com/loginUsingApim: -1 undefined","error":"Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference"}```
And in log i see the error :-
An unexpected error occured
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class
java.lang.Object.getClass()' on a null object reference
at cy0.<init>(chromium-TrichromeWebViewGoogle.aab-stable-556311633:4)
at com.android.webview.chromium.a.setCookie(chromium-TrichromeWebViewGoogle.aab-stable-556311633:4)
at com.getcapacitor.plugin.CapacitorCookieManager.setCookie(CapacitorCookieManager.java:123)
at com.getcapacitor.plugin.CapacitorCookieManager.put(CapacitorCookieManager.java:176)
at com.android.okhttp.internal.http.HttpEngine.receiveHeaders(HttpEngine.java:891)at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:625)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:475)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:542)
at
com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:106)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:30)
at com.silkimen.http.HttpRequest.code(HttpRequest.java:1447)
at com.silkimen.http.HttpRequest.stream(HttpRequest.java:1740)
at com.silkimen.http.HttpRequest.buffer(HttpRequest.java:1729)
at com.silkimen.http.HttpRequest.receive(HttpRequest.java:1856)
at com.silkimen.cordovahttp.CordovaHttpBase.processResponse(CordovaHttpBase.java:195)
at com.silkimen.cordovahttp.CordovaHttpBase.run(CordovaHttpBase.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:463)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
at java.lang.Thread.run(Thread.java:1012)
My Package.json file contains :-
```"dependencies": {
"@angular/common": "^14.2.12",
"@angular/core": "^14.2.12",
"@angular/forms": "^14.2.12",
"@angular/platform-browser": "^14.2.12",
"@angular/platform-browser-dynamic": "^14.2.12",
"@angular/router": "^14.2.12",
"@awesome-cordova-plugins/core": "^5.40.0",
"@awesome-cordova-plugins/email-composer": "^5.40.0",
"@awesome-cordova-plugins/screen-orientation": "^5.41.0",
"@awesome-cordova-plugins/social-sharing": "^5.40.0",
"@capacitor/android": "4.7.3",
"@capacitor/app": "^4.0.0",
"@capacitor/core": "^4.0.0",
"@capacitor/haptics": "^4.0.0",
"@capacitor/ios": "^4.0.0",
"@capacitor/keyboard": "^4.0.0",
"@capacitor/preferences": "^4.0.0",
"@ionic-native/app-availability": "^5.31.0",
"@ionic-native/app-version": "^5.36.0",
"@ionic-native/core": "^5.33.1",
"@ionic-native/file": "^5.31.1",
"@ionic-native/http": "^5.34.0",
"@ionic-native/in-app-browser": "^5.36.0",
"@ionic-native/ionic-webview": "^5.36.0",
"@ionic-native/local-notifications": "^5.36.0",
"@ionic-native/network": "^5.33.1",
"@ionic-native/pdf-generator": "^5.34.0",
"@ionic-native/social-sharing": "^5.36.0",
"@ionic-native/sqlite": "^5.33.1",
"@ionic-native/sqlite-porter": "^5.33.1",
"@ionic-native/web-intent": "^5.36.0",
"@ionic-native/zip": "^5.36.0",
"@ionic/angular": "^6.3.8",
"@ionic/storage": "^3.0.6",
"@ionic/storage-angular": "^3.0.6",
"@obsidize/rotating-file-stream": "1.1.0",
"@obsidize/rx-console": "2.0.2",
"@types/crypto-js": "^4.1.1",
"@types/hammerjs": "^2.0.41",
"chart.js": "^3.7.0",
"com-darryncampbell-cordova-plugin-intent": "^2.2.0",
"cordova-plugin-advanced-http": "3.2.0",
"cordova-plugin-androidx": "^3.0.0",
"cordova-plugin-androidx-adapter": "^1.1.3",
"cordova-plugin-appavailability": "^0.4.2",
"cordova-plugin-email-composer": "^0.10.0",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-fullscreen": "^1.3.0",
"cordova-plugin-inappbrowser": "^5.0.0",
"cordova-plugin-market": "^1.2.0",
"cordova-plugin-network-information": "^3.0.0",
"cordova-plugin-screen-orientation": "^3.0.2",
"cordova-plugin-x-socialsharing": "^6.0.3",
"cordova-zip-plugin": "^2.0.0",
"crypto-js": "^4.1.1",
"d3": "7.0.1",
"es6-promise-plugin": "^4.2.2",
"file-saver": "^2.0.5",
"hammerjs": "^2.0.8",
"handlebars": "^4.7.7",
"intent-plugin": "^0.0.1",
"ionic-pullup": "6.1.0-beta.1",
"js-htmlencode": "^0.3.0",
"jszip": "^3.9.1",
"moment": "^2.29.1",
"ng-circle-progress": "^1.6.0",
"rxjs": "~6.6.0",
"tslib": "~2.0.0",
"xlsx": "^0.18.5",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^14.2.10",
"@angular-eslint/builder": "^14.2.0",
"@angular-eslint/eslint-plugin": "^14.2.0",
"@angular-eslint/eslint-plugin-template": "^14.2.0",
"@angular-eslint/template-parser": "^14.2.0",
"@angular/cli": "^14.2.10",
"@angular/compiler": "^14.2.12",
"@angular/compiler-cli": "^14.2.12",
"@angular/language-service": "^14.2.12",
"@capacitor/cli": "^4.0.0",
"@ionic-native/app-version": "^5.36.0",
"@ionic/angular-toolkit": "^7.0.0",
"@types/jasmine": "~3.6.0",
"@types/jasminewd2": "~2.0.3",
"@types/jquery": "^3.5.6",
"@types/node": "^12.20.47",
"@typescript-eslint/eslint-plugin": "4.16.1",
"@typescript-eslint/parser": "4.16.1",
"cordova-pdf-generator": "^2.1.1",
"cordova-sqlite-storage": "^6.0.0",
"cordova.plugins.diagnostic": "^6.0.3",
"eslint": "^7.6.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jsdoc": "30.7.6",
"eslint-plugin-prefer-arrow": "1.2.2",
"jasmine-core": "4.5.0",
"jasmine-spec-reporter": "7.0.0",
"karma": "~6.4.1",
"karma-chrome-launcher": "~3.1.1",
"karma-coverage": "~2.2.0",
"karma-coverage-istanbul-reporter": "~3.0.3",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "^2.0.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"typescript": "~4.6.4",
"uk.co.workingedge.cordova.plugin.sqliteporter": "^1.1.1"
}
}
Has anyone faced same issue ? it seems to work fine when i comment out the below code in CapacitorCookieManager.json ni the location
node_modules@capacitor\android\capacitor\src\main\java\com\getcapacitor\plugin
public void setCookie(String url, String value) {
//webkitCookieManager.setCookie(url, value);
//flush();
}
答案1
得分: 1
这个问题在 Capacitor v5 中已经修复了。问题历史 可以查看,也在更新日志中有提及。
英文:
I believe this has been fixed in Capacitor v5. The issue history is available and it is referenced in the changelog.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论