Send JSON as parameter in url using RestTemplate

If you try to send the json as a parameter in url via Spring’s RestTemplate, you will encounter the following error:

HttpClientErrorException$BadRequest: 400 : [{"Message":"Wrong format. See specification description; Unexpected character ('%' (code 37)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: (String)\... (541 bytes)]

In order to solve this problem, you need to:

  1. Encode the URL yourself
  2. Disable url encoding at the RestTemplate level.

Let’s do that:

private String encodeUrl(String apiBaseUrl) throws Exception {
    URIBuilder b = new URIBuilder(apiBaseUrl);
    b.addParameter("jsonArg", "{\"field1\":\"value1\"}");
    b.addParameter("simpleArg", "value2");
    return b.build().toString();
}

RestTemplate restTemplate = new RestTemplate();
...
DefaultUriBuilderFactory defaultUriBuilderFactory = new DefaultUriBuilderFactory();
defaultUriBuilderFactory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE);
restTemplate.setUriTemplateHandler(defaultUriBuilderFactory);

String url = encodeUrl("http://localhost:8080");
String response = restTemplate.getForObject(url, String.class);

Many thanks to Chris Liu for showing how to disable url encoding in RestTemplate: http://www.chrispad.com/2019/04/disable-encoding-url-using-resttemplate.html.

If you still have any questions, feel free to ask me in the comments under this article, or write me on promark33@gmail.com.

If I saved your day, you can support me :)

One thought on “Send JSON as parameter in url using RestTemplate

  1. We are happy to welcome you!

    Sending newsletters of Your commercial offers via follow-up forms to the sites of companies via any countries and domain zones of the world.

    website =» contact-forms.su

    WHAT IS THE MAILING OF WEBSITES BY CONTACT FORMS?
    This is a type of mailing using the contact forms that are located in the contact section of the website and filled by our robot in automatic mode with a rate of a few thousand contact forms per 1 minute, while the alphanumeric code from the pictures (captcha) is also solved.
    After that, the letters including your commercial offers are sent to the e-mail addresses of organisations.
    When sending mailing by contact contact forms, it turns out that each website sends a letter “to itself” and, therefore, all letters arrive in the inbox folder of the exact e-mail in which the firm is ready to receive the commercial information.

    Unique Trade Offer:
    Fast one hundred % notification of businesses and internet resource owners about new commercial offers.
    Search of new customers that other advertisements cannot find.

    AIM:
    Finding customers that cannot be found through other types of advertisements.

    Benefits:
    1.100% delivery of cooperation letters.
    2.Expansion of the client base.
    3. Increase of the market segment.
    4.Mailings based on topics and regionality.
    5. Sending e-mails to company officials.
    6. Conducting tenders.
    7. Conducting marketing campaigns.
    8. Studying public opinion and conducting surveys.
    9. Fast notofication.
    10. Price.
    11. Entering the markets of other countries.

    Undeniable advantages:
    1.When sending mailing by feedback forms, all e-mails arrive in the inbox folder. When sending e-newsletters, this can reach up to 5%.

    2.When sending mailing by feedback forms it is possible to send a few million letters per day to inbox folders. When sending e-newsletters a few thousands arrive in the inbox folders, the remaining ones often either do not reach or fill the junk.

    3. When sending mailing by feedback forms a letter does not get blocked by mail services because it is sent from different websites. When sending e-mail newsletters it is possible to send a few thousands of those but nevertheless all the IP addresses from which the mailing is done will be in “BAN”.

    4. When sending mailing by contact forms the very little amount of macro-synonims is used to form headings and text of the letter. When sending e-newsletters, it is necessary to use synonyms («macros») for each word and create thousands different headings.

    5. A lot of firms try to hide their electronic address and only leave a contact form for contacting with them.

    6. When sending mass e-mails, your commercial offer can be delivered to every employee of the company, (which causes irritation) compared to mailing by contact forms where the letter is received at the electronic address specifically set up for business offers.

    7.1/2 part of business electronic addresses are placed on free mail systems, they are not very “searchable” by mailbox, but when sending mailing by contact forms through these e-mail servers, all letters are 100-percent delivered to the recipients.

    8. Only 30%-40% of organisations are published in the directories within several years, and all the other ones are already placed in our WHOIS databases and are waiting for your cooperation offers.
    It turns out that that e-mails of companies from directories are full of spam, which means that they will not have such outcome as when sending mailing by feedback forms using our the newest VOIS databases.

    9. Any kind of stop words in the body or headings of the message can be sent through contact forms. When sending bulk e-mails, such messages either are not delivered the recipient or end up in a junk folder.
    The list of stop words of mail systems includes almost all phrases and words that encourage recipients to take active actions.

    Application:

    1. Expanding the customer base.
    2. Quick notification of marketplaces about new cooperation offers.
    3. Informing company officials.
    4.Testing the demand for products and services.
    5. Conducting tenders.
    6.Conducting marketing research.
    7.Studying public opinion and conducting surveys.
    8. Searching for clients in other countries.

    Reasons for ordering this service:

    1. 100% delivery of your messages and business offers to millions of companies all over the globe.
    Every internet resource sends a e-mail to itself so all filters of mail systems are bypassed.

    2.Mailing by feedback forms is an ideal way in in terms of conducting all sorts of marketing researches, surveys and studies of social opinion on differentdirection and type of activity.
    When sending mailing by contact forms, you will be sure that your letter has been delivered to 100-percent of consumers of your product and service and if a service or product is “poorly promoted”, then the potential problem lies in in something else, for example in cost.
    At the same time, within 7 days you will see real demand for your products and services, you will not need to spend money on renting an office and other more time-consuming and expensive marketing activities.

    3.Mailing by feedback forms is the most economical and quickest way to get your service or product to the markets of other states.

    4. Mailing by feedback forms is a great tool for conducting all sorts of tenders.

    5.Monthly update of the database, as more than 150,000 new sites, are registered all over the world daily, and you, get new potential customers.

    6. Full geographical scope for all countries of the world.

    7. We offer customers that you will not find through other advertisement.
    When sending mailing by contact forms, you will be able to get to that part of your potential customers, that are impossible to find automatically in another way.
    For instance, you will be able to deliver a business offer to those potential clients that were earlier out of reach due to e-mail filters while sending e-newsletters.
    In reality, there is a paradoxical situation: businesses in the directories are literally filled with spam with all sorts of business offers while very little or no e-mails are sent to the remaining ones.

    8. Unique technique of unraveling the captcha.
    There are special services for decrypting numeric and alphabetic code (captcha/CAPTCHA). It costs 1 dollar to solve thousand CAPTCHAs.
    It follows from this that, processing one million websites the program unravels a million CAPTCHAs, which costs thousand $ only to decrypt captcha/CAPTCHA, and we provide this free of charge for you!

    9. By ordering mailing by feedback forms, you are promoting your product or service not to separate individuals, but to collectives, for instance domain .com, where more than one hundred and fifty million cooperational firms from all countries of the world are accumulated (we have got samples of them from all international zones for every country).

    10. Mailing by contact forms also includes a type of SMS mailing
    E-mail that is linked to the contact form is the primary electronic address of businesses through which orders and business offers are sent. This mail is also set up for cell phones as it is necessary to respond to the messages very fast so as not to misplace the application or the relevance of the cooperation offer.

    11. The base of countries also includes all joint businesses from all countries of the world working with or closely related to this country, for instance, diasporas and national communities.
    Sanctions of mail systems and search engines?
    These mailings are an alternative to sending mass e-mails, therefore search engine sanctions and “BAN” do not apply to them.
    Mail service delivers the data of messages to the inbox folder, as it moves through the “warm channel” from the new IP address of the internet resource to the corporate electronic address of the same site.
    In simple language, these mailings “live in letters” and mail filters do not respond to them, because mails have trust in communication channels between internet resources and corporate emails.

    OUR DATABASES:
    You can buy our databases separately from the mailing by sending us a request by contact form.

    MORE THAN 2000 VOIS DATABASES BY DOMAIN ZONES AND COUNTRIES.

    COLLECTIONS OF DATABASES BY THE MAIN CONTINENTS OF THE WORLD.

    SELECTIONS OF DATABASES BY THE MAIN LANGUAGES.

    COLLECTIONS OF DATABASES BY THE MAIN CMS.

    COLLECTIONS OF DATABASES BY THE MAIN COUNTRIES.

    HOW TO MAKE AN ORDER FOR MAILING BY CONTACT FORMS:
    The simplest text + headings, the main goal is to interest the potential customer, and they will read the rest on your site.
    Most likely, all ads on your subject are already on the Internet networks, enter the necessary requests into the search bar and choose the most interesting ones.
    The headings are substituted randomly from text file.
    Only messages in the text form are sent, links are inserted without problems, they are active. If the potential customer needs pictures or more specific information, then you should forward the customer to visit your website.

    In the letter:
    Text without pictures, since pictures do not pass through the feedback form.
    Your contact details:
    Internet resource address:

    Fields to fill in:
    Name:
    Country:
    City:
    Website:
    Several headings:
    E-mail for autoresponces:

    website =» contact-forms.su
    Price List =» contact-forms.su/en/price/

Leave a Reply

Your email address will not be published.