I know this thead is an old thread, but solved in part my problem I had for 3 days.
So may this can be useful for other users have the same problem.
Many thanks
@aeric for the tips.
I have launched an http python server to serve files in local, just on a served folder of my pc I launched
python -m http-server
From my tests on android emulator using localhost:8000 httpjob always refused a connection, after this I tried 127.0.0.1:8000 and same, didn't worked.
Now thanks to you I realized that localhost of emulator is not the same localhost of my pc, but just point to android device itself, in this case the emulator.
Searching on the web now I found a tip to use 10.0.2.2 to point pc localhost, and that works.
Now I can connect from emulator to my pc localhost but for some strange reasons I cannot download the served python http-server files.
Here my code that now connect after changing localhost to 10.0.2.2
DownloadAndSaveFile ("http://10.0.2.2:8000/examples/models/gcode/benchy.gcode")
Sub DownloadAndSaveFile (Link As String)
Dim j As HttpJob
j.Initialize("", Me)
j.Download(Link)
' j.GetRequest.SetHeader("Access-Control-Allow-Origin", "*")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim out As OutputStream = File.OpenOutput(File.DirInternal, "benchy.gcode", False)
File.Copy2(j.GetInputStream, out)
out.Close '<------ very important
Log("DONE")
Else
Log("ERROR: " & j.ErrorMessage)
End If
j.Release
End Sub
And this is the httpjob error:
on server side, on the command prompt I see connection, but python says file not found, but pointing with a browser it ask to download and I can download it.
Note that I have this on the manifest:
' 28 - Non-ssl (non-https) communication is not permitted by default.
' It can be enabled in B4A v9+ by adding this line to the manifest editor:
CreateResourceFromFile(Macro, Core.NetworkClearText)