| copyright |
|
||
|---|---|---|---|
| lastupdated | 2017-04-27 |
{:new_window: target="_blank"} {:shortdesc: .shortdesc} {:screen:.screen} {:codeblock:.codeblock}
{: #sdk-network-request}
You can also use the BMSCore SDK to make network requests to any resource.
{: #request-android}
-
Make sure you have 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);
{: codeblock}
The Request class is a simple way to make an HTTP request and get the response after the request is completed. If you are 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.
{: #request-ios}
-
Make sure you have imported the Client SDK and initialized it in your iOS application.
-
Create a network request.
{: #ios-swift3 notoc}
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)
{: codeblock}
{: #ios-swift22 notoc}
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)
{: codeblock}
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 progress of uploads, and pausing or canceling requests. To get the responses, you have the option to choose either completion handlers or delegates.
The BMSURLSession class is available for iOS only.
For complete usage examples, see the BMSCore GitHub README.
{: #request-cordova}
-
Make sure you have imported the Client SDK and initialized it in your Cordova application.
-
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);
{: codeblock}