本文整理汇总了Java中com.squareup.okhttp.ResponseBody.string方法的典型用法代码示例。如果您正苦于以下问题:Java ResponseBody.string方法的具体用法?Java ResponseBody.string怎么用?Java ResponseBody.string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.okhttp.ResponseBody
的用法示例。
在下文中一共展示了ResponseBody.string方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
import com.squareup.okhttp.ResponseBody; //导入方法依赖的package包/类
/**
*
* @param params
* @return
*/
@Override
protected String doInBackground(Void... params) {
OkHttpClient client = new OkHttpClient();
HttpUrl httpUrl = HttpUrl.parse(COIN_DESK_API_URL);
//System.out.println("Requesting : " + httpUrl.toString());
FormEncodingBuilder formBody = new FormEncodingBuilder();
formBody.add("lastHours", "24");
formBody.add("maxRespArrSize", "24");
Request request = new Request.Builder()
.url(httpUrl)
.post(formBody.build())
.build();
String content = null;
try {
Response response = client.newCall(request).execute();
ResponseBody body = response.body();
if (isZipped(response)) {
content = unzip(body);
} else {
content = body.string();
}
body.close();
} catch (IOException e) {
e.printStackTrace();
}
return content;
}
示例2: doInBackground
import com.squareup.okhttp.ResponseBody; //导入方法依赖的package包/类
/**
*
* @param params
* @return
*/
@Override
protected String doInBackground(Void... params) {
OkHttpClient client = new OkHttpClient();
HttpUrl httpUrl = HttpUrl.parse(TwitterSearchURL);
httpUrl = httpUrl.newBuilder()
.addQueryParameter("q", _searchTerm)
.addQueryParameter("lang", "en")
.addQueryParameter("result_type", "recent")
.build();
Request request = new Request.Builder()
.url(httpUrl)
.addHeader("Authorization", "Bearer " + _bearerToken)
.addHeader("Accept-Encoding", "gzip")
.build();
String content = null;
try {
Response response = client.newCall(request).execute();
ResponseBody body = response.body();
if (isZipped(response)) {
content = unzip(body);
} else {
content = body.string();
}
body.close();
} catch (IOException e) {
e.printStackTrace();
}
return content;
}
示例3: convert
import com.squareup.okhttp.ResponseBody; //导入方法依赖的package包/类
@Override public T convert(ResponseBody value) throws IOException {
String str = value.string();
try {
int start = str.indexOf("\"pagebean\":") + "\"pagebean\":".length();
int end = str.indexOf(",\"ret_code\"");
return gson.fromJson(str.substring(start, end), type);
} finally {
}
}
示例4: fromResponseBody
import com.squareup.okhttp.ResponseBody; //导入方法依赖的package包/类
@Override
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
if (String.class.equals(type)) {
return new Converter<ResponseBody, String>() {
@Override
public String convert(ResponseBody value) throws IOException {
return value.string();
}
};
}
return null;
}
示例5: fromResponseBody
import com.squareup.okhttp.ResponseBody; //导入方法依赖的package包/类
@Override
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
if (String.class.equals(type)) {
return new Converter<ResponseBody, String>() {
@Override public String convert(ResponseBody value) throws IOException {
return value.string();
}
};
}
return null;
}
示例6: extractBody
import com.squareup.okhttp.ResponseBody; //导入方法依赖的package包/类
private String extractBody(ResponseBody body) {
if (body != null) {
try {
return body.string();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}