Answer the question
In order to leave comments, you need to log in
How to send text in UTF-8?
How to encode text in UTF-8 so that VK accepts?
public static void main(String[] args) throws Exception {
HttpHost proxy = new HttpHost("127.0.0.1", 8888, "http");
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
builder.build());
HttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(sslsf)
.setDefaultRequestConfig(RequestConfig.custom()
.setProxy(proxy)
.setCookieSpec(CookieSpecs.STANDARD).build())
.build();
HttpPost httpPost = new HttpPost("https://api.vk.com/method/messages.send");
HttpEntity entity = MultipartEntityBuilder
.create()
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
.addTextBody("user_id", "")
.addTextBody("message", "Что бы тут я не написал в сообщении будут вопросы")
.addTextBody("access_token", "")
.addTextBody("v", "5")
.build();
httpPost.setEntity(entity);
System.out.println (httpPost.getURI());
HttpResponse response1 = httpClient.execute(httpPost);
String responseString = new BasicResponseHandler().handleResponse(response1);
System.out.println(responseString);
System.out.println(response1.getStatusLine());
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question