On B4J (8.50) I try to connect to a Web Service (on private network) with this code:
But I have an error on line 244 into the library:
Is the first time that I use Web Services and a friend send to me a JS code that connect at this Web Service:
Have you got some suggest?
B4X:
Dim su As StringUtils
Dim url As String="https://myurl/ws"
Dim usr As String=su.EncodeBase64("CREDENTIALS".GetBytes("UTF8"))
Dim aut As String=$"AuthString"$
Dim j As HttpJob
j.Initialize("",Me )
j.GetRequest.SetHeader("Authorization",aut)
j.GetRequest.SetContentType("application/json")
j.PostString(url,usr)
Wait For(j) JobDone(j As HttpJob)
If j.Success Then
Log(j.GetString)
Else
Log(j.ErrorMessage)
End If
j.Release
But I have an error on line 244 into the library:
Waiting for debugger to connect...
Program started.
Error occurred on line: 244 (HttpJob)
java.lang.NullPointerException
at anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest.SetHeader(OkHttpClientWrapper.java:470)
at b4j.example.main$ResumableSub_AppStart.resume(main.java:134)
at b4j.example.main._appstart(main.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.start(main.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
at java.lang.Thread.run(Thread.java:748)
Is the first time that I use Web Services and a friend send to me a JS code that connect at this Web Service:
JavaScript:
function send_local(){
var url = "https://myurl/ws"
var cr = "CREDENTIALS";
var cr64 = btoa(cr);
var auth = "authString";
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
console.log(req.responseText);
}else{
console.log(req);
}
};
req.open("POST", url, true);
req.setRequestHeader('Authorization',auth);
req.setRequestHeader('Content-Type','application/json; charset=utf-8');
Have you got some suggest?