Call an URL without opening a browser window

2019-07-15 21:33发布

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?

2条回答
可以哭但决不认输i
2楼-- · 2019-07-15 21:57

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.

  1. Use curl utility for your operating system and
  2. Use POSTMAN utility, and call the your code by just submitting the request.
  3. Write a client code in your favorite language that will mock your browsers call.
  4. Write a shell script or windows batch file that eventually call any of above.
查看更多
仙女界的扛把子
3楼-- · 2019-07-15 22:19

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);
查看更多
登录 后发表回答