K
K
Kirill Zhilyaev2017-08-30 15:39:01
Java
Kirill Zhilyaev, 2017-08-30 15:39:01

How to send text in UTF-8?

How to encode text in UTF-8 so that VK accepts?

spoiler
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

1 answer(s)
I
Ivan, 2017-08-30
@bessovesti

String utf8String = new String("abcd".getBytes(), "UTF-8");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question