@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 nullprivate static void close(HttpMethod method) {method.rel
去获取解析正文 连接并解析响应流。 安装 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 post去获取,response返回码是302,返回的code放在header的Location中。 请求的时候client_id,response_type,redirect_uri,state拼接在url后面,account和password放在body表单(x-...
CloseableHttpResponse response = httpclient.execute(httppost); try { HttpEntity entity = response.getEntity(); if (entity != null) { System.out.println("----------------------------...
在开发时,我通过构造 OkHttpClient 对象发起一次请求并加入队列,待服务端响应后,回调 Callback 接口触发 onResponse() 方法,然后在该方法中通过 Response 对象处理返回结果、实现业务逻辑。代码大致如下: /...
client.post(String url, Object body) -> CompleteableFuture<Response> client.put(String url, Object body) -> CompleteableFuture<Response> client.delete(String url) -> CompleteableFuture<Response> ...
它不使用 cURL 或其他外部库。... // Just print the response body 也可以这样写: <?php require_once ( 'httpclient.php' ); $ http = new HttpClient ( "http://mydomain.com/info.php" ); $ http -> g
tornado协程的理解示例 编写协程函数 from tornado import gen from tornado.httpclient import AsyncHTTPClient @gen.coroutine def coroutine_visit(): ... response = yield http_client.fetch... print(response.body)
渠道 针对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" ] :
Java的世界里,HttpClient 是一个功能强大的Http请求库,然而接口非常复杂,设计上遵从正交性,简单的请求也需要写比较多的代码,更不要说隐藏在各种细节里面的高级用法了。Requests, 是一个模仿python requests ...
HttpClient client = new HttpClient(); String response = null; String keyword = null; PostMethod postMethod = new PostMethod(url); // try { // if (param != null) // keyword = new...
去取解压 解压缩用 gzip 压缩的响应体。安装 npm install --...HttpClient() .use(decompress()) .use(parseBody()) .get('http://www.digitaledgeit.com.au/', function(error, response) { console.log( error, re
错误写法 ... self.write(response.body) @gen.coroutine def httpClient(url): result = yield httpclient.AsyncHTTPClient().fetch(url) return result 按照一般的方法return会报错 需要使用
JavaMail.jsp代码: *"%> *"%> *"%> *,java.io.*"%> ;charset=utf8"%> ... response.sendRedirect("../indexSelf.jsp");//转向某页 }catch (Exception e){ e.printStackTrace(); } %> </body> </html>
$ transport = new \ HttpClient \ Transport \ Socks (); $ transport -> setHost ( 'http-client.serbang' ); try { $ transport -> connect (); $ transport -> request ()-> setPath ( '/tests/providers/...