I have an aplication wich I use to register some items. I want to store thoose at an online database, for that matter I created a simple php page that receives the variables via URL and adds them to a database. I can get things working swiftly by calling the browser intent and opening the URL, but thats kind of boring. Is there any other way to call my URL without opening the browser and still run the php code?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It would be a web service call, see this thread... How to call a SOAP web service on Android
Technically, any time you call a web url to do something (ex: a simple php page that receives the variables via URL and adds them to a database) its a web service. Now in your case its likely it does not use SOAP and have a WSDL, but its more of a RESTful type setup, in which you post the data and it processes it.
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("http://www.example.com/" + URL);
response = httpClient.execute(httpGet, localContext);
回答2:
Yes, you could do it by choosing any one of following options among multiple options available. All below option will mock browser behavior and eventually execute call your PHP service.
- Use curl utility for your operating system and
- Use POSTMAN utility, and call the your code by just submitting the request.
- Write a client code in your favorite language that will mock your browsers call.
- Write a shell script or windows batch file that eventually call any of above.