Put breakpoint and inspect the value of "Test".
Put breakpoint and inspect the value of "Test".
MULTITHREADING SUCCESS.
New problem
org.apache.http.conn.HttpHostConnectException: Connection to http://localhost:8732 refused
Y U NO LET ME
You have something listening on that port, right?
Firewall? It's above the usual 1024 restricted range...
Edit: Is it because your Android emulator doesn't have something running there, instead that's on your local physical machine, so you need to traverse the network correctly to break out of the VM? Try using an IP address.
http://developer.android.com/resourc...localhostalias
Referring to localhost from the emulated environment
If you need to refer to your host computer's localhost, such as when you want the emulator client to contact a server running on the same host, use the alias 10.0.2.2 to refer to the host computer's loopback interface. From the emulator's perspective, localhost (127.0.0.1) refers to its own loopback interface.
Last edited by Daneel Trevize; May 24 2012 at 10:34:47 AM.
Yes it is that. I am an idiot.
Now I've almost got there, it's getting the response from the web service, but it's not setting it to the textbox output for fuck only knows what reason.
// Read response data
char[] buffer = new char[(int)responseEntity.getContentLength()];
InputStream stream = responseEntity.getContent();
InputStreamReader reader = new InputStreamReader(stream);
reader.read(buffer);
stream.close();
JSONArray helloresponse = new JSONArray(new String(buffer));
tv.setText(helloresponse.toString());
tv.setVisibility(View.VISIBLE);
Y U NO GO
(helloresponse contains the information i would expect, btw)
EDIT: FIXT
Last edited by Dark Flare; May 24 2012 at 11:42:06 AM. Reason: FIXT
Yup, got it.
Now time to build in authentication! This will be an interesting day.
Okay so kinda working.
The string I get back from the Auth is like so:
{"Authed":true,"Level":1,"Name":"test"}
What's the best way to split up and handle this data? It's a JSON response if that makes any difference. Basically what I want it to do at this stage is push to a new screen (via Intent, is that right for UI flow?) where it'll display a list of things based on what the level set is (higher level can see MOAR THINGS), and also output the name at the top of the screen or something (which I know how to do, obv, I just don't know how to split up that data that's passed back from the call).
Isn't there a JSON deserializer (which should unpack the data into an array or an object) built-in?
ed: haven't really tried my hand at this whole mobile developemnt thing so I'm not sure what resources you have at our disposal, but System.Web.Extensions.dll.JavaScriptSerializer (.NET 3.5) should be able to parse it.
Last edited by halka; May 25 2012 at 12:16:57 PM.
All expressed opinions match those of my employers, hail satan
Sorry I should have specified, it's on the android that I wish to turn it into something I can manipulate.
By jove I do believe I'm getting there. Can now handle it as an object and interrogate the properties.
Now I just need to use the interrogation of the "Authed" property to decide whether or not to pass to a NEW SCREEN.
I do hope you're not trusting the response from the network as to whether a secret/secure screen should be displayed. Sure you have the server dictate what level a user is at, and then decide to present them controls or not with which to send different requests to the server, but please don't be having some privileged info in your android client that you will reveal to someone/anyone who manages to supply some specific text in a HTTP response.
Yeah the new screen is just going to be a series of buttons that fire off further web calls to the server with credentials from the phone, don't worry!
Another programming question, this one work-related.
NOTE: The language I'm working with is PHP 5.3something
Currently, my work codebase has a bunch of controllers classes that extend a Secure_Controller class. They also have various AJAX functions for retrieving data, none of which are really standardized - leading to potential security issues, duplicated code, etc. I want to solve this by creating a standarized function that all AJAX calls will pass through. My initial idea (a shitty one) was to do something like this:
So the URL /derp/ajax/urinateViolently will call Derp::doSomethingElse()Code:class Derp extends Secure_Controller { public function ajax($urlSegment) { $params = $this->input->post(); switch($urlSegment) { case 'poop': $data = $this->doSomething($params['haduuuur']); break; case 'urinateViolently': $data = $this->doSomethingElse($params['herp']; break'; //so on and so forth } $this->output->set_header('Content-type:application/json'); $this->output->set_output(json_encode($data)); } }
Except that's terrible - you have to update the function EVERY TIME you want to enable another AJAX call. It's not that much better than just implementing them without any kind of consistency.
This led me to another idea, however - implement an AJAX delegate function in the secure controller class and using a string at the end of the functions to denote its availability to be used for an AJAX call:
Thus, the functions being implemented here would look something like this:Code:class Secure_Controller { public function ajax($task) { $params = $this->input->post(); $functionName = $task . 'ForAjax'; $data = array(); if(method_exists($this, $functionName) { $data = $this->$functionName($params); } $this->output->set_header('Content-type:application/json'); $this->output->set_output(json_encode($data)); } }
The primary downside of this is that if some dumb shit just happens to use a function that ends with "ForAjax" its output will end up returned, but I've checked the codebase and there are no such functions. I feel like I can do better than this, but I don't want developers to have to manually update a registry of AJAX-capable functions. What's your input, FHC programmers?Code:Derp::pooForAjax($params) /* called from /derp/ajax/poo */ Derp::urinateViolentlyForAjax($params) /* called from /derp/ajax/urinateViolently */
Last edited by Tarminic; May 30 2012 at 11:38:58 PM.
![]()
![]()
Status of Babby: 100% Formed
Bookmarks