Created
April 7, 2014 06:44
-
-
Save zero-master/10015747 to your computer and use it in GitHub Desktop.
issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getJsonResponse(String target, Map params) { | |
params.addAll({ | |
'client_id':this.client_id, 'api_key':this.api_key | |
}); | |
var url = new Uri.http(API_HOST, target, params); | |
var client = new HttpClient(); | |
client.userAgent = 'DoD v1.0'; | |
print(url); | |
var url2 = Uri.parse('http://google.com'); | |
return client.getUrl(url).then((HttpRequest req) { | |
req.headers.add('content-type', 'application/json'); | |
return req.close(); | |
}).then((HttpResponse resp) { | |
var json = ''; | |
if (resp.statusCode == 200) { | |
resp.transform(UTF8.decoder) // use a UTF8.decoder | |
.listen((String data) => json = json + data, // output the data | |
onError: (error) => print("UNABLE TO CONNECT"), onDone:() { | |
print(json); // works fine | |
return json; // not working | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment