P PierPaduan Active Member Licensed User Longtime User Jun 15, 2017 #1 Hi, I have an HttpJob where I'm trying to set the header in the following way. LastToken is sent from the server to the client. Code: Copy Dim TokenHeaderName As String = "Authorization" Dim j2 As HttpJob j2.Initialize("send", Me) j2.GetRequest.SetHeader(TokenHeaderName, LastToken) j2.PostString(link_server, StringaJSON ) but I obtain the following error. Any suggestion to fix this problem? Thanks a Lot to everyone. Best regards. Error occurred on line: 83 (HttpJob) java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.http.client.methods.HttpRequestBase.setHeader(java.lang.String, java.lang.String)' on a null object reference at anywheresoftware.b4a.http.HttpClientWrapper$HttpUriRequestWrapper.SetHeader(HttpClientWrapper.java:449) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:742) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134) at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262) at it.ritmo.setandgopro.service2._pacchettizza_e_spedisci_sendlist(service2.java:863) at it.ritmo.setandgopro.service2._spedizione_sendlist(service2.java:842) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:697) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134) at anywheresoftware.b4a.BA$2.run(BA.java:328) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5951) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) Click to expand...
Hi, I have an HttpJob where I'm trying to set the header in the following way. LastToken is sent from the server to the client. Code: Copy Dim TokenHeaderName As String = "Authorization" Dim j2 As HttpJob j2.Initialize("send", Me) j2.GetRequest.SetHeader(TokenHeaderName, LastToken) j2.PostString(link_server, StringaJSON ) but I obtain the following error. Any suggestion to fix this problem? Thanks a Lot to everyone. Best regards. Error occurred on line: 83 (HttpJob) java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.http.client.methods.HttpRequestBase.setHeader(java.lang.String, java.lang.String)' on a null object reference at anywheresoftware.b4a.http.HttpClientWrapper$HttpUriRequestWrapper.SetHeader(HttpClientWrapper.java:449) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:742) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134) at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262) at it.ritmo.setandgopro.service2._pacchettizza_e_spedisci_sendlist(service2.java:863) at it.ritmo.setandgopro.service2._spedizione_sendlist(service2.java:842) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:697) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134) at anywheresoftware.b4a.BA$2.run(BA.java:328) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5951) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) Click to expand...
DonManfred Expert Licensed User Longtime User Jun 15, 2017 #2 Did you marked okhttp library too in your project? Upvote 0
P PierPaduan Active Member Licensed User Longtime User Jun 15, 2017 #3 I don't have Okhttp lib, but the old http lib. Upvote 0
DonManfred Expert Licensed User Longtime User Jun 15, 2017 #4 i suggest to switch to the new okhttputils and the new okhttp Upvote 0
P PierPaduan Active Member Licensed User Longtime User Jun 15, 2017 #5 Thanks Don, but I cannot switch to new okhttps because I use an old version of B4A that don't have those libs in the internal libs. Any other suggestion? Thanks Upvote 0
Thanks Don, but I cannot switch to new okhttps because I use an old version of B4A that don't have those libs in the internal libs. Any other suggestion? Thanks
Erel B4X founder Staff member Licensed User Longtime User Jun 15, 2017 #6 Your code is wrong. Correct code: https://www.b4x.com/android/forum/threads/set-http-request-header-with-httputils2.39413/#content Upvote 0
Your code is wrong. Correct code: https://www.b4x.com/android/forum/threads/set-http-request-header-with-httputils2.39413/#content
P PierPaduan Active Member Licensed User Longtime User Jun 16, 2017 #7 Erel said: Your code is wrong. Correct code: https://www.b4x.com/android/forum/threads/set-http-request-header-with-httputils2.39413/#content Click to expand... FIXED !!! Thanks a Lot Erel. Code: Copy Dim j2 As HttpJob j2.Initialize("send", Me) j2.PostString(link_server, StringaJSON ) j2.GetRequest.SetHeader(TokenHeaderName, LastToken) Upvote 0
Erel said: Your code is wrong. Correct code: https://www.b4x.com/android/forum/threads/set-http-request-header-with-httputils2.39413/#content Click to expand... FIXED !!! Thanks a Lot Erel. Code: Copy Dim j2 As HttpJob j2.Initialize("send", Me) j2.PostString(link_server, StringaJSON ) j2.GetRequest.SetHeader(TokenHeaderName, LastToken)