`

httpclient response body

 
阅读更多
@Test
	public void testHttpClient3() throws Exception {
		HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
		CloseableHttpClient closeableHttpClient = httpClientBuilder.build();

		ClassLoader classLoader = getClass().getClassLoader();
		File jsonTemplateFile = new File(classLoader.getResource(
				"dailyNotifyTemplate.json").getFile());
		System.out.println("jsonTemplateFile:" + jsonTemplateFile.getAbsolutePath());
		String JSON_STRING = FileUtils.readFileToString(jsonTemplateFile);
		String userOpenId = "oz1rJs-TVjVxCJVjMKgdqO_pFtxx";
		JSON_STRING = JSON_STRING.replace("REPLACE_TO_USER", userOpenId);
		System.out.println(JSON_STRING);
		StringEntity requestEntity = new StringEntity(JSON_STRING,
				ContentType.APPLICATION_JSON);
		String token = "sOm0jUot4hFrjdT1UJNQhufJEKTJQtFqbGqtup16S_s1-SFkNJWk0WhnBcd5fRlvha59QLYg3DXDgRDpYEMAbfp5WLyZj1GwzvQrPjeiWMQ";
		String uri = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
				+ token;
		HttpPost method = new HttpPost(uri);
		method.setEntity(requestEntity);
		HttpResponse result = closeableHttpClient.execute(method);
		String resData = EntityUtils.toString(result.getEntity());
		JSONObject json = (JSONObject) new JSONParser().parse(resData);
		System.out.println("errcode:" + json.get("errcode"));
		System.out.println("errmsg:" + json.get("errmsg"));
		System.out.println("msgid:" + json.get("msgid"));
	}

分享到:
评论

相关推荐

    HttpClient 卡死 response 为 null - 帐前卒 - CSDN1

    HttpClient response nullprivate static void close(HttpMethod method) {method.rel

    parse-body:解析并连接响应正文

    去获取解析正文 连接并解析响应流。 安装 npm install --save go-fetch-parse-body... .get('https://api.github.com/repos/go-fetch-js/parse-body', {'User-Agent': 'go-fetch'}, function(error, response) { con

    HttpClient获取OAuth2.0中的code

    通过httpclient post去获取,response返回码是302,返回的code放在header的Location中。 请求的时候client_id,response_type,redirect_uri,state拼接在url后面,account和password放在body表单(x-...

    HttpClient以及获取页面内容应用

    CloseableHttpResponse response = httpclient.execute(httppost); try { HttpEntity entity = response.getEntity(); if (entity != null) { System.out.println("----------------------------...

    OkHttp踩坑随笔为何 response.body().string() 只能调用一次

    在开发时,我通过构造 OkHttpClient 对象发起一次请求并加入队列,待服务端响应后,回调 Callback 接口触发 onResponse() 方法,然后在该方法中通过 Response 对象处理返回结果、实现业务逻辑。代码大致如下: /...

    AytchTeeTeePee:一个更好的、CompletableFuture 友好的 HTTPClient

    client.post(String url, Object body) -> CompleteableFuture<Response> client.put(String url, Object body) -> CompleteableFuture<Response> client.delete(String url) -> CompleteableFuture<Response> ...

    httpclient:PHP Http 客户端

    它不使用 cURL 或其他外部库。... // Just print the response body 也可以这样写: <?php require_once ( 'httpclient.php' ); $ http = new HttpClient ( "http://mydomain.com/info.php" ); $ http -> g

    tornado协程示例

    tornado协程的理解示例 编写协程函数 from tornado import gen from tornado.httpclient import AsyncHTTPClient @gen.coroutine def coroutine_visit(): ... response = yield http_client.fetch... print(response.body)

    channel:针对ORC即将推出的Nim渠道实施

    渠道 针对ORC即将推出的Nim渠道实施 ... echo response.body[ 0 .. 20 ] proc worker = var client = newHttpClient () var data: JsonNode ch. recv (data) if data != nil : for url in data[ "url" ] :

    HTTP请求库java-requests.zip

    Java的世界里,HttpClient 是一个功能强大的Http请求库,然而接口非常复杂,设计上遵从正交性,简单的请求也需要写比较多的代码,更不要说隐藏在各种细节里面的高级用法了。Requests, 是一个模仿python requests ...

    java 爬网 程序 示例

    HttpClient client = new HttpClient(); String response = null; String keyword = null; PostMethod postMethod = new PostMethod(url); // try { // if (param != null) // keyword = new...

    decompress:解压用 gzip 压缩的响应体

    去取解压 解压缩用 gzip 压缩的响应体。安装 npm install --...HttpClient() .use(decompress()) .use(parseBody()) .get('http://www.digitaledgeit.com.au/', function(error, response) { console.log( error, re

    Tornado协程在python2.7如何返回值(实现方法)

    错误写法 ... self.write(response.body) @gen.coroutine def httpClient(url): result = yield httpclient.AsyncHTTPClient().fetch(url) return result 按照一般的方法return会报错 需要使用

    JavaMail jsp发送邮件

    JavaMail.jsp代码: *"%> *"%> *"%> *,java.io.*"%> ;charset=utf8"%> ... response.sendRedirect("../indexSelf.jsp");//转向某页 }catch (Exception e){ e.printStackTrace(); } %> </body> </html>

    http-client:用于与 API 通信的基本 HTTP 客户端

    $ transport = new \ HttpClient \ Transport \ Socks (); $ transport -> setHost ( 'http-client.serbang' ); try { $ transport -> connect (); $ transport -> request ()-> setPath ( '/tests/providers/...

Global site tag (gtag.js) - Google Analytics