Making a network request
You can use the BMSCore
SDK to make network requests to any resource.
Android
-
Make sure you imported the Client SDK and initialized it in your Android application.
-
Make a network request.
String customResourceURL = "<your resource URL>"; Request request = new Request(customResourceURL, "GET"); ResponseListener listener = new ResponseListener() { @Override public void onSuccess(Response response) { Log.i("MyApp", "Response: " + response.getResponseText()); } @Override public void onFailure(Response response, Throwable t, JSONObject extendedInfo) { Log.i("MyApp", "Request failed. Response: " + response.getResponseText() + ". Error: " + t.getLocalizedMessage()); } }; request.send(getApplicationContext(), listener);
The Request
class is a simple way to make an HTTP request and get the response after the request is completed. If you're downloading or uploading large files or large bodies of data, you can use the Request
download
or upload
methods. To monitor the progress of the download or upload, create a custom ProgressListener
and pass it to the download
or upload
methods.
For complete usage examples, see the BMSCore
GitHub README.
iOS
-
Make sure that you imported the Client SDK and initialized it in your iOS app.
-
Create a network request.
Swift 3.0
let customResourceURL = "<your resource URL>" let request = Request(url: customResourceURL, method: HttpMethod.GET) let callBack:BMSCompletionHandler = {(response: Response?, error: Error?) in if error == nil { print ("Response: \(response?.responseText), no error") } else { print ("Error: \(error)") } } request.send(completionHandler: callBack)
Swift 2.2
let customResourceURL = "<your resource URL>" let request = Request(url: customResourceURL, method: HttpMethod.GET) let callBack:BMSCompletionHandler = {(response: Response?, error: NSError?) in if error == nil { print ("Response: \(response?.responseText), no error") } else { print ("Error: \(error)") } } request.send(completionHandler: callBack)
The Request
class is a simple way to make an HTTP request and get the response after the request is completed. If you want more flexibility and control than what you can get from the Request
class, you can use the BMSURLSession
class. Some features of the BMSURLSession
class include monitoring the progress of uploads, and pausing or canceling requests. To get the responses, you can select either completion handlers or delegates.
The BMSURLSession
class is available for iOS only.
For complete usage examples, see the BMSCore
GitHub README.
Cordova
-
Make sure that you imported the Client SDK and initialized it in your Cordova app.
-
Create a network request.
var success = function(data) { console.log("success", data); } var failure = function(error) {console.log("failure", error); } var request = new BMSRequest("<your application route>", BMSRequest.GET); request.send(success, failure);