Transforming Curl into Java equivalent?



  • Hello! Can anyone say either the existence of an interpreter Curl in Java or any (although roughly) analog to the Java code will be from this request:

     curl -i -X POST --data-urlencode "oauth_consumer_key=ЗНАЧЕНИЕ" --
     data-urlencode "oauth_nonce=значение"  --data-urlencode "oauth_signature_method=HMAC-SHA1" --data-urlencode "oauth_timestamp=значение"  --data-urlencode "oauth_version=1.0" --data-
     urlencode "oauth_token=значение"  --data-urlencode "auth_signature=значение" --data "category=3" --data-urlencode "title=Новое название" --data-urlencode "description=Краткое описание" --data-urlencode "message=Полное описание" --data 
    "end2br_desc=1&includehtml_desc=no" http://yoursite.ucoz.ru/uapi/news
    

    Thank you for the answer!



  • You don't have to think about the Curl, but about the HTTP client in principle. There's a lot of HTTP-client reality for Java. One of the most famous... https://hc.apache.org/httpcomponents-client-ga/

    HttpClient httpClient = HttpClients.createDefault();
    HttpUriRequest request = RequestBuilder.post("http://yoursite.ucoz.ru/uapi/news")
            .addParameter("oauth_consumer_key", "ЗНАЧЕНИЕ")
            .addParameter("oauth_nonce", "значение")
            .addParameter("oauth_signature_method", "HMAC-SHA1")
            .addParameter("oauth_timestamp", "значение")
            .addParameter("oauth_version", "1.0")
            .addParameter("oauth_token", "значение")
            .addParameter("auth_signature", "значение")
            .addParameter("title", "Новое название")
            .addParameter("description", "Краткое описание")
            .addParameter("message", "Полное описание")
            .setEntity(new UrlEncodedFormEntity(Arrays.asList(
                    new BasicNameValuePair("end2br_desc", "1"),
                    new BasicNameValuePair("includehtml_desc", "no")
            ))).build();
    HttpResponse response = httpClient.execute(request);
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2