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 8034581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:04:07+00:00 2026-06-05T02:04:07+00:00

I’m trying to send a POST using Groovy HTTPBuilder but the data I want

  • 0

I’m trying to send a POST using Groovy HTTPBuilder but the data I want to send is already URL-encoded so I want HTTPBuilder to POST it as is. I tried the following:

def validationString = "cmd=_notify-validate&" + postData
def http = new HTTPBuilder(grailsApplication.config.grails.paypal.server)
http.request(Method.POST) {
    uri.path = "/"
    body = validationString
    requestContentType = ContentType.TEXT

    response.success = { response ->
            println response.statusLine
    }
}

But it gives me a NullPointerException:

java.lang.NullPointerException
at groovyx.net.http.HTTPBuilder$RequestConfigDelegate.setBody(HTTPBuilder.java:1200)
  • 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-06-05T02:04:08+00:00Added an answer on June 5, 2026 at 2:04 am

    Since you’re using pre-encoded form values you cannot use the default map-based content type encoder. You must specify the content type so the EncoderRegistry knows how to handle the body.

    You may create the HttpBuilder with a content type that specifies the body is a URL-encoded string:

    def http = new HTTPBuilder(url, ContentType.URLENC)
    

    Or make the request passing the content type explicitly:

    http.request(Method.POST, ContentType.URLENC) {
      // etc.
    

    For reference, here’s how I figured it out–I didn’t know before I read the question.

    • Looked at the request method’s API docs to see what the closure was expected to contain. I’ve used HTTPBuilder only in passing, so I wanted to see what, specifically, the body “should” be, or “may” be, and if the two were different.
    • The four-arg version of the request method links to the RequestConfigDelegate class and said the options were discussed in its docs.
    • The RequestConfigDelegate.setBody method, which is what the body setter is, states the body “[…] may be of any type supported by the associated request encoder. That is, the value of body will be interpreted by the encoder associated with the current request content-type.”
    • The request encoder link is to the EncoderRegistry class. It has an encode_form method taking a string and states it “assumes the String is an already-encoded POST string”. Sounds good.
    • The request content-type link was to an HttpBuilder inner class method, RequestConfigDelegate.getRequestContentType, which in turn had a link to the ContentType enum.
    • That enum has a URLENC value that led me to believe it’d be the best first guess.
    • I tried the HTTPBuilder ctor taking a content type, and that worked.
    • Circled back to the request methods and noticed there’s a version also taking a content type.

    I’d guess the total time was ~5-10 minutes, much shorter than it took to type up what I did. Hopefully it’ll convince you, though, that finding this kind of stuff out is possible via the docs, in relatively short order.

    IMO this is a critical skill for developers to groom, and make you look like a hero. And it can be fun.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to construct a data frame in an Rcpp function, but when I
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.