The OkHttp library defaults to GET requests, but it also provides tools for sending POST requests and parameters with minimal code. My demo app already packages parameters and other request info, so I'll show how to adapt my code for either type of request.
- [Instructor] I previously described how to use…the OkHTTP library to make HTTP requests.…And showed how much simpler the code is…than when you use the HTTP URL connection class,…so far my code is only handling get requests,…but you also have to be able to handle post requests…and OkHTTP makes it easy to do that as well.…I'm working in the project which picks up…where the last project left off, and I'm going to add…a bit of code here, right before I build my request object.…I already have conditional code in place to handle…get requests up here, so now I will add a bit of code…that looks for a post request.…
Once again, I'll look for request…package.get_method.equals and then I'll pass in…a literal string of post, just like I did…with HTTP URL connection, my job is to take…the parameters that are being passed in to me…and then wrap them into the body of the request.…I don't have to do that as manually as I did…with HTTP URL connection, instead, I'm going to use…an API from OkHTTP called a multipart body…and a request body, I'll start off with…
IInstructor David Gassner starts with an overview discussion about available networking strategies, and then dives into how to declare networking permissions, make network requests, handle responses, parse data returned from a web service, and pass user credentials to services that support HTTP basic authentication. He also provides an overview of popular higher-level networking libraries, including OkHttp and Picasso, and offers recommendations for improving performance in network-connected apps. David also covers using static feeds, using dynamic PHP pages hosted on a public server web service, and integrating apps with network data storage.
- Integrating mobile apps
- Communicating with Android
- Preventing app freezes with background threads
- Preparing an app for network communication
- Declaring permissions
- Checking network connectivity
- Retrieving data over the web
- Using traditional APIs
- Using third-party libraries