barx Well-Known Member Licensed User Longtime User Jun 13, 2014 #1 Hi all, I am currently working on a web project that is being written using the CakePHP framework. The framwork supports Digest authentication. I need to make an Android app to compliment the system. The app will be use to collate data and store locally and then once on a wifi connection, the data will be uploaded to the web project. Now I need this to be relatively secure, so going with digest as SSL is not available. Never really done anything http with b4a so if anyone has a basic example of how to do the auth and how to put and get data I would be eternally grateful. I know it's a lot to ask but I have no idea where to start. Well, not strictly true as I know I need to start with the Http lib, but that is as far as I have got, lol
Hi all, I am currently working on a web project that is being written using the CakePHP framework. The framwork supports Digest authentication. I need to make an Android app to compliment the system. The app will be use to collate data and store locally and then once on a wifi connection, the data will be uploaded to the web project. Now I need this to be relatively secure, so going with digest as SSL is not available. Never really done anything http with b4a so if anyone has a basic example of how to do the auth and how to put and get data I would be eternally grateful. I know it's a lot to ask but I have no idea where to start. Well, not strictly true as I know I need to start with the Http lib, but that is as far as I have got, lol
DonManfred Expert Licensed User Longtime User Jun 13, 2014 #2 Setting Job.Username and Job.Password before sendind the request (httpjob) does not work? Code: Copy Dim job As HttpJob job.Initialize("testhtaccess",Me) job.Username = "myusername" job.Password = "mypassword" job.Download("http://mydomain:8080/test.php") this calls the test.php which is in a HTACCESS secured folder Last edited: Jun 13, 2014 Upvote 0
Setting Job.Username and Job.Password before sendind the request (httpjob) does not work? Code: Copy Dim job As HttpJob job.Initialize("testhtaccess",Me) job.Username = "myusername" job.Password = "mypassword" job.Download("http://mydomain:8080/test.php") this calls the test.php which is in a HTACCESS secured folder
barx Well-Known Member Licensed User Longtime User Jun 13, 2014 #3 I have not tried anything yet as I didn't know where to start. Been reading articles all day, my eyes are burning out Upvote 0
I have not tried anything yet as I didn't know where to start. Been reading articles all day, my eyes are burning out
DonManfred Expert Licensed User Longtime User Jun 13, 2014 #4 barx said: I have not tried anything yet as I didn't know where to start. Click to expand... Starting at httputils Tutorial is a good start i think. Search for other examples (there are a lot). Feel free to ask if you encounter any problems barx said: Been reading articles all day, my eyes are burning out Click to expand... Dont read too much! ;-) PS: I have tested the above code-example on my own xampp server on my pc. But with real username and password Upvote 0
barx said: I have not tried anything yet as I didn't know where to start. Click to expand... Starting at httputils Tutorial is a good start i think. Search for other examples (there are a lot). Feel free to ask if you encounter any problems barx said: Been reading articles all day, my eyes are burning out Click to expand... Dont read too much! ;-) PS: I have tested the above code-example on my own xampp server on my pc. But with real username and password
barx Well-Known Member Licensed User Longtime User Jun 15, 2014 #5 looking at the logs, the request is GET Code: Copy 192.168.0.12 - - [15/Jun/2014:21:17:10 +0100] "GET /pvcollection/sites/pull/HFDH0001.json HTTP/1.1" 302 - The framework I am using requires it to be a POST. doing a cURL request as POST from another machine works fine Code: Copy 127.0.0.1 - admin [15/Jun/2014:21:00:47 +0100] "POST /pvcollection/sites/pull/HFDH0001.json HTTP/1.1" 200 303 any way to get it to be POST??? Upvote 0
looking at the logs, the request is GET Code: Copy 192.168.0.12 - - [15/Jun/2014:21:17:10 +0100] "GET /pvcollection/sites/pull/HFDH0001.json HTTP/1.1" 302 - The framework I am using requires it to be a POST. doing a cURL request as POST from another machine works fine Code: Copy 127.0.0.1 - admin [15/Jun/2014:21:00:47 +0100] "POST /pvcollection/sites/pull/HFDH0001.json HTTP/1.1" 200 303 any way to get it to be POST???
DonManfred Expert Licensed User Longtime User Jun 15, 2014 #6 barx said: any way to get it to be POST??? Click to expand... Have a look at PostString. Upvote 0
barx Well-Known Member Licensed User Longtime User Jun 16, 2014 #7 I think I'm not quite getting this. The request I am making is like so... Code: Copy //server/pvcollections/sites/pull/HFDH0001.json Which in effect is /server/path-to-wwwroot/controller/action/param.json The .json tells the framework that I would like the response in json format I was doing Code: Copy Dim httpAction as HttpJob httpAction.Initialize("Get Site", Me) httpAction.Username = "admin" httpAction.Password = "test" httpAction.Download(Shared.GetSetting("h") & "/pvcollection/sites/pull/" & txtSiteRef.text & ".json") Now if I do this with Basic or Digest auth enabled on framework I get a redirect response and I believe this is because the request is GET method and needs to be POST. If I disable auth, it works nice (so at least I know it is auth that is issue) after reply above I tried PostString Code: Copy httpAction.PostString(Shared.GetSetting("host") & "/pvcollection/sites/pull/", txtSiteRef.text & ".json") or httpAction.PostString(Shared.GetSetting("host") & "/pvcollection/sites/pull/" txtSiteRef.text & ".json", "") Both give me the same error java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=/pvcollection/sites/pull/ Click to expand... The host setting above is returned as expected (Shared.GetSetting("host")). So, I'm kinda lost again p.s. thanks so far @DonManfred, Upvote 0
I think I'm not quite getting this. The request I am making is like so... Code: Copy //server/pvcollections/sites/pull/HFDH0001.json Which in effect is /server/path-to-wwwroot/controller/action/param.json The .json tells the framework that I would like the response in json format I was doing Code: Copy Dim httpAction as HttpJob httpAction.Initialize("Get Site", Me) httpAction.Username = "admin" httpAction.Password = "test" httpAction.Download(Shared.GetSetting("h") & "/pvcollection/sites/pull/" & txtSiteRef.text & ".json") Now if I do this with Basic or Digest auth enabled on framework I get a redirect response and I believe this is because the request is GET method and needs to be POST. If I disable auth, it works nice (so at least I know it is auth that is issue) after reply above I tried PostString Code: Copy httpAction.PostString(Shared.GetSetting("host") & "/pvcollection/sites/pull/", txtSiteRef.text & ".json") or httpAction.PostString(Shared.GetSetting("host") & "/pvcollection/sites/pull/" txtSiteRef.text & ".json", "") Both give me the same error java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=/pvcollection/sites/pull/ Click to expand... The host setting above is returned as expected (Shared.GetSetting("host")). So, I'm kinda lost again p.s. thanks so far @DonManfred,
barx Well-Known Member Licensed User Longtime User Jun 16, 2014 #8 ok, I fixed that error, I wasn't appending "http://". Using the post strings above I now seem to get a POST request sent but it still doesn't authenticate Upvote 0
ok, I fixed that error, I wasn't appending "http://". Using the post strings above I now seem to get a POST request sent but it still doesn't authenticate
DonManfred Expert Licensed User Longtime User Jun 16, 2014 #9 barx said: doing a cURL request as POST from another machine works fine Code: Copy 127.0.0.1 - admin [15/Jun/2014:21:00:47 +0100] "POST /pvcollection/sites/pull/HFDH0001.json HTTP/1.1" 200 303 Click to expand... That´s a POST-Request made from the machine the server is running on. 127.0.0.1 is localhost. Are you sure the request came from an other machine?? Maybe a firewall/router Issue? Upvote 0
barx said: doing a cURL request as POST from another machine works fine Code: Copy 127.0.0.1 - admin [15/Jun/2014:21:00:47 +0100] "POST /pvcollection/sites/pull/HFDH0001.json HTTP/1.1" 200 303 Click to expand... That´s a POST-Request made from the machine the server is running on. 127.0.0.1 is localhost. Are you sure the request came from an other machine?? Maybe a firewall/router Issue?
DonManfred Expert Licensed User Longtime User Jun 16, 2014 #10 Please post the CURL code you made the request with so we see what you are calling with curl there. Upvote 0
barx Well-Known Member Licensed User Longtime User Jun 18, 2014 #11 OK made a little progress but not quite there. I have got Basic authentication working, but not Digest. Digest works from the browser but NOT cURL or app. Which I don't reeally understand and they should all be singing from the same book. Code: Copy curl --digest --user admin:admin http://127.0.0.1/pvcollection/sites/pull/HFDH0001.json Also tried it with a -d to make the request POST. Upvote 0
OK made a little progress but not quite there. I have got Basic authentication working, but not Digest. Digest works from the browser but NOT cURL or app. Which I don't reeally understand and they should all be singing from the same book. Code: Copy curl --digest --user admin:admin http://127.0.0.1/pvcollection/sites/pull/HFDH0001.json Also tried it with a -d to make the request POST.
DonManfred Expert Licensed User Longtime User Jun 18, 2014 #12 Do you have an url which i can test here? Maybe with login credentials which just see a note after successful authenticating? Upvote 0
Do you have an url which i can test here? Maybe with login credentials which just see a note after successful authenticating?
barx Well-Known Member Licensed User Longtime User Jun 18, 2014 #13 Unfortunately Don, this is currently running locally on my laptop in wamp. I'm just about to wrap up for the night, so I'll look at setting up a port forward and making it available to online. Not sure how far I will get as I don't know if my ISP allows port 80 servers, may have to change port, etc. I'll PM you some details if I get it live and leave laptop live until I hear back. Upvote 0
Unfortunately Don, this is currently running locally on my laptop in wamp. I'm just about to wrap up for the night, so I'll look at setting up a port forward and making it available to online. Not sure how far I will get as I don't know if my ISP allows port 80 servers, may have to change port, etc. I'll PM you some details if I get it live and leave laptop live until I hear back.
DonManfred Expert Licensed User Longtime User Jun 18, 2014 #14 it is a php running at the end, yes? And you have secured a folder with a .htaccess-file? Send me the .htaccess in pm if you use a .htaccess to do the authentification Upvote 0
it is a php running at the end, yes? And you have secured a folder with a .htaccess-file? Send me the .htaccess in pm if you use a .htaccess to do the authentification