Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6345665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:52:02+00:00 2026-05-24T20:52:02+00:00

I want to send post request to some service using Java. Requests must contain

  • 0

I want to send post request to some service using Java. Requests must contain some parameters and one of them is multiline String. I tried many ways but everytime I end up with whole text submitted as single line without newline characters. Any ideas?

URL url = new URL("http://example.com/create");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
String data = "param1=value&string=" + convertNewLineCharacters(text);
writer.write(data);
writer.flush();

// (...)
private String convertNewLineCharacters(String text) throws Exception  {
  String encodedString = URLEncoder.encode(text, "UTF-8");
  encodedString = encodedString.replaceAll("%0A", "\r\n");

  return encodedString;
}

I am limited to standard Java Api, so no external libraries are allowed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:52:07+00:00Added an answer on May 24, 2026 at 8:52 pm
    // ...
    conn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" ); // not sure it is important
    // ...
    writer.write(URLEncoder.encode(data, "UTF-8")); // urlencode the whole string and do not edit it
    // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to send some strings in a list in a POST call. eg:
I want to send some pings after post something to my blog. As you
I want to send some information from PHP to Java. Why? Because I have
I have an access token and i want to send the POST request and
In my application I want to send a SOAP request to some url, the
I basically want to make an ajax post to send some stateId and get
I'm using curl to do post request, for some reason it prints xml response,
I want to send a xml file to my wcf service , how can
I have to send some parameter to an IFRAME with POST method. I have
I've got a problem using WebClient.UploadStringAsync method. I've to do a POST request with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.