IONIC – cordova-plugin-advanced-http post call fails with Cookie Error

huangapple go评论61阅读模式
英文:

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  :-

```{&quot;headers&quot;:{&quot;normalizedNames&quot;:{},&quot;lazyUpdate&quot;:null,&quot;headers&quot;:{}},&quot;status&quot;:-1,&quot;statusText&quot;:&quot;Unknown Error&quot;,&quot;url&quot;:&quot;https://ddomain.com/loginUsingApim&quot;,&quot;ok&quot;:false,&quot;name&quot;:&quot;HttpErrorResponse&quot;,&quot;message&quot;:&quot;Http failure response for https://ddomain.com/loginUsingApim: -1 undefined&quot;,&quot;error&quot;:&quot;Attempt to invoke virtual method &#39;java.lang.Class java.lang.Object.getClass()&#39; on a null object reference&quot;}```


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 :-
```&quot;dependencies&quot;: {
&quot;@angular/common&quot;: &quot;^14.2.12&quot;,
&quot;@angular/core&quot;: &quot;^14.2.12&quot;,
&quot;@angular/forms&quot;: &quot;^14.2.12&quot;,
&quot;@angular/platform-browser&quot;: &quot;^14.2.12&quot;,
&quot;@angular/platform-browser-dynamic&quot;: &quot;^14.2.12&quot;,
&quot;@angular/router&quot;: &quot;^14.2.12&quot;,
&quot;@awesome-cordova-plugins/core&quot;: &quot;^5.40.0&quot;,
&quot;@awesome-cordova-plugins/email-composer&quot;: &quot;^5.40.0&quot;,
&quot;@awesome-cordova-plugins/screen-orientation&quot;: &quot;^5.41.0&quot;,
&quot;@awesome-cordova-plugins/social-sharing&quot;: &quot;^5.40.0&quot;,
&quot;@capacitor/android&quot;: &quot;4.7.3&quot;,
&quot;@capacitor/app&quot;: &quot;^4.0.0&quot;,
&quot;@capacitor/core&quot;: &quot;^4.0.0&quot;,
&quot;@capacitor/haptics&quot;: &quot;^4.0.0&quot;,
&quot;@capacitor/ios&quot;: &quot;^4.0.0&quot;,
&quot;@capacitor/keyboard&quot;: &quot;^4.0.0&quot;,
&quot;@capacitor/preferences&quot;: &quot;^4.0.0&quot;,
&quot;@ionic-native/app-availability&quot;: &quot;^5.31.0&quot;,
&quot;@ionic-native/app-version&quot;: &quot;^5.36.0&quot;,
&quot;@ionic-native/core&quot;: &quot;^5.33.1&quot;,
&quot;@ionic-native/file&quot;: &quot;^5.31.1&quot;,
&quot;@ionic-native/http&quot;: &quot;^5.34.0&quot;,
&quot;@ionic-native/in-app-browser&quot;: &quot;^5.36.0&quot;,
&quot;@ionic-native/ionic-webview&quot;: &quot;^5.36.0&quot;,
&quot;@ionic-native/local-notifications&quot;: &quot;^5.36.0&quot;,
&quot;@ionic-native/network&quot;: &quot;^5.33.1&quot;,
&quot;@ionic-native/pdf-generator&quot;: &quot;^5.34.0&quot;,
&quot;@ionic-native/social-sharing&quot;: &quot;^5.36.0&quot;,
&quot;@ionic-native/sqlite&quot;: &quot;^5.33.1&quot;,
&quot;@ionic-native/sqlite-porter&quot;: &quot;^5.33.1&quot;,
&quot;@ionic-native/web-intent&quot;: &quot;^5.36.0&quot;,
&quot;@ionic-native/zip&quot;: &quot;^5.36.0&quot;,
&quot;@ionic/angular&quot;: &quot;^6.3.8&quot;,
&quot;@ionic/storage&quot;: &quot;^3.0.6&quot;,
&quot;@ionic/storage-angular&quot;: &quot;^3.0.6&quot;,
&quot;@obsidize/rotating-file-stream&quot;: &quot;1.1.0&quot;,
&quot;@obsidize/rx-console&quot;: &quot;2.0.2&quot;,
&quot;@types/crypto-js&quot;: &quot;^4.1.1&quot;,
&quot;@types/hammerjs&quot;: &quot;^2.0.41&quot;,
&quot;chart.js&quot;: &quot;^3.7.0&quot;,
&quot;com-darryncampbell-cordova-plugin-intent&quot;: &quot;^2.2.0&quot;,
&quot;cordova-plugin-advanced-http&quot;: &quot;3.2.0&quot;,
&quot;cordova-plugin-androidx&quot;: &quot;^3.0.0&quot;,
&quot;cordova-plugin-androidx-adapter&quot;: &quot;^1.1.3&quot;,
&quot;cordova-plugin-appavailability&quot;: &quot;^0.4.2&quot;,
&quot;cordova-plugin-email-composer&quot;: &quot;^0.10.0&quot;,
&quot;cordova-plugin-file&quot;: &quot;^6.0.2&quot;,
&quot;cordova-plugin-fullscreen&quot;: &quot;^1.3.0&quot;,
&quot;cordova-plugin-inappbrowser&quot;: &quot;^5.0.0&quot;,
&quot;cordova-plugin-market&quot;: &quot;^1.2.0&quot;,
&quot;cordova-plugin-network-information&quot;: &quot;^3.0.0&quot;,
&quot;cordova-plugin-screen-orientation&quot;: &quot;^3.0.2&quot;,
&quot;cordova-plugin-x-socialsharing&quot;: &quot;^6.0.3&quot;,
&quot;cordova-zip-plugin&quot;: &quot;^2.0.0&quot;,
&quot;crypto-js&quot;: &quot;^4.1.1&quot;,
&quot;d3&quot;: &quot;7.0.1&quot;,
&quot;es6-promise-plugin&quot;: &quot;^4.2.2&quot;,
&quot;file-saver&quot;: &quot;^2.0.5&quot;,
&quot;hammerjs&quot;: &quot;^2.0.8&quot;,
&quot;handlebars&quot;: &quot;^4.7.7&quot;,
&quot;intent-plugin&quot;: &quot;^0.0.1&quot;,
&quot;ionic-pullup&quot;: &quot;6.1.0-beta.1&quot;,
&quot;js-htmlencode&quot;: &quot;^0.3.0&quot;,
&quot;jszip&quot;: &quot;^3.9.1&quot;,
&quot;moment&quot;: &quot;^2.29.1&quot;,
&quot;ng-circle-progress&quot;: &quot;^1.6.0&quot;,
&quot;rxjs&quot;: &quot;~6.6.0&quot;,
&quot;tslib&quot;: &quot;~2.0.0&quot;,
&quot;xlsx&quot;: &quot;^0.18.5&quot;,
&quot;zone.js&quot;: &quot;~0.11.4&quot;
},
&quot;devDependencies&quot;: {
&quot;@angular-devkit/build-angular&quot;: &quot;^14.2.10&quot;,
&quot;@angular-eslint/builder&quot;: &quot;^14.2.0&quot;,
&quot;@angular-eslint/eslint-plugin&quot;: &quot;^14.2.0&quot;,
&quot;@angular-eslint/eslint-plugin-template&quot;: &quot;^14.2.0&quot;,
&quot;@angular-eslint/template-parser&quot;: &quot;^14.2.0&quot;,
&quot;@angular/cli&quot;: &quot;^14.2.10&quot;,
&quot;@angular/compiler&quot;: &quot;^14.2.12&quot;,
&quot;@angular/compiler-cli&quot;: &quot;^14.2.12&quot;,
&quot;@angular/language-service&quot;: &quot;^14.2.12&quot;,
&quot;@capacitor/cli&quot;: &quot;^4.0.0&quot;,
&quot;@ionic-native/app-version&quot;: &quot;^5.36.0&quot;,
&quot;@ionic/angular-toolkit&quot;: &quot;^7.0.0&quot;,
&quot;@types/jasmine&quot;: &quot;~3.6.0&quot;,
&quot;@types/jasminewd2&quot;: &quot;~2.0.3&quot;,
&quot;@types/jquery&quot;: &quot;^3.5.6&quot;,
&quot;@types/node&quot;: &quot;^12.20.47&quot;,
&quot;@typescript-eslint/eslint-plugin&quot;: &quot;4.16.1&quot;,
&quot;@typescript-eslint/parser&quot;: &quot;4.16.1&quot;,
&quot;cordova-pdf-generator&quot;: &quot;^2.1.1&quot;,
&quot;cordova-sqlite-storage&quot;: &quot;^6.0.0&quot;,
&quot;cordova.plugins.diagnostic&quot;: &quot;^6.0.3&quot;,
&quot;eslint&quot;: &quot;^7.6.0&quot;,
&quot;eslint-plugin-import&quot;: &quot;2.22.1&quot;,
&quot;eslint-plugin-jsdoc&quot;: &quot;30.7.6&quot;,
&quot;eslint-plugin-prefer-arrow&quot;: &quot;1.2.2&quot;,
&quot;jasmine-core&quot;: &quot;4.5.0&quot;,
&quot;jasmine-spec-reporter&quot;: &quot;7.0.0&quot;,
&quot;karma&quot;: &quot;~6.4.1&quot;,
&quot;karma-chrome-launcher&quot;: &quot;~3.1.1&quot;,
&quot;karma-coverage&quot;: &quot;~2.2.0&quot;,
&quot;karma-coverage-istanbul-reporter&quot;: &quot;~3.0.3&quot;,
&quot;karma-jasmine&quot;: &quot;~5.1.0&quot;,
&quot;karma-jasmine-html-reporter&quot;: &quot;^2.0.0&quot;,
&quot;protractor&quot;: &quot;~7.0.0&quot;,
&quot;ts-node&quot;: &quot;~8.3.0&quot;,
&quot;typescript&quot;: &quot;~4.6.4&quot;,
&quot;uk.co.workingedge.cordova.plugin.sqliteporter&quot;: &quot;^1.1.1&quot;
}
}

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.

huangapple
  • 本文由 发表于 2023年4月17日 20:25:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76035143.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定