本文整理汇总了Java中ch.boye.httpclientandroidlib.entity.StringEntity类的典型用法代码示例。如果您正苦于以下问题:Java StringEntity类的具体用法?Java StringEntity怎么用?Java StringEntity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringEntity类属于ch.boye.httpclientandroidlib.entity包,在下文中一共展示了StringEntity类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dispatchJSONPostRequest
import ch.boye.httpclientandroidlib.entity.StringEntity; //导入依赖的package包/类
public JSONObject dispatchJSONPostRequest(ApiSpec apiSpec, String requestPath, JSONObject jsonObject, AuthCredentials authCredentials) throws TeslaApiException {
try {
final URI uri = new URI(apiSpec.scheme, null, apiSpec.host, apiSpec.port, apiSpec.getPathForRequestPath(requestPath), null, null);
Log.d(Config.TAG, "Executing request: " + uri.toURL());
if(jsonObject != null){
Log.d(Config.TAG, "Params: " + jsonObject.toString());
}
final HttpPost httpPost = new HttpPost(uri);
if (authCredentials != null) {
apiSpec.authModule.authorizeRequest(httpPost, authCredentials);
}
httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
if (jsonObject != null){
httpPost.setEntity(new StringEntity(jsonObject.toString(), "UTF-8"));
}
return executeRequest(httpPost);
} catch (UnsupportedEncodingException | URISyntaxException | MalformedURLException e) {
throw new TeslaApiException(e);
}
}
示例2: simulate400
import ch.boye.httpclientandroidlib.entity.StringEntity; //导入依赖的package包/类
public static HttpResponse simulate400() {
HttpResponse response = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), 400, "Bad Request") {
@Override
public HttpEntity getEntity() {
try {
return new StringEntity("16");
} catch (UnsupportedEncodingException e) {
// Never happens.
return null;
}
}
};
return response;
}
示例3: SilkHttpBody
import ch.boye.httpclientandroidlib.entity.StringEntity; //导入依赖的package包/类
public SilkHttpBody(String body) {
try {
mEntity = new StringEntity(body, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: stringEntityWithContentTypeApplicationJSON
import ch.boye.httpclientandroidlib.entity.StringEntity; //导入依赖的package包/类
protected static StringEntity stringEntityWithContentTypeApplicationJSON(String s) {
StringEntity e = new StringEntity(s, "UTF-8");
e.setContentType("application/json");
return e;
}
示例5: jsonEntity
import ch.boye.httpclientandroidlib.entity.StringEntity; //导入依赖的package包/类
public static StringEntity jsonEntity(JSONObject body)
throws UnsupportedEncodingException {
StringEntity entity = new StringEntity(body.toJSONString(), "UTF-8");
entity.setContentType("application/json");
return entity;
}
示例6: jsonEntity
import ch.boye.httpclientandroidlib.entity.StringEntity; //导入依赖的package包/类
/**
* Helper for turning a JSON object into a payload.
* @throws UnsupportedEncodingException
*/
protected static StringEntity jsonEntity(JSONObject body) {
return stringEntityWithContentTypeApplicationJSON(body.toJSONString());
}