Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

400
Views
Vapor: sending post requests

I am trying to send an HTTP request using Vapor, to verify a recaptcha

Google's Captcha api is defined as follows:

URL: https://www.google.com/recaptcha/api/siteverify METHOD: POST

POST Parameter Description
secret Required. The shared key between your site and reCAPTCHA.
response  Required. The user response token provided by the reCAPTCHA client-side integration on your site. 
remoteip Optional. The user's IP address. 

So I need to make a POST request with 2 parameters (secret and response).

In Swift i have:

func routes(_ app: Application throws {
    app.on(.POST, "website_form") { req -> EventLoopFuture<View> in
        var form: FromRequest = /*initial values*/
        /*decode form data*/
        
        do {
            req.client.post("https://www.google.com/recaptcha/api/siteverify") { auth_req in
                try auth_req.content.encode(CaptchaRequestBody(secret: "6Lfoo98dAAAAALRlUoTH9LhZukUHRPzO__2L0k3y", response: form.recaptcha_response), as: .formData)
                auth_req.headers = ["Content-Type": "application/x-www-form-urlencoded"]
            }.whenSuccess { resp_val in
                print("Response: \(resp_val)")
            }
        }
    } 
    /* More code */
}

struct CaptchaRequestBody: Content {
    let secret: String
    let response: String
}

After running the post request, I get following error code:

{
  "success": false,
  "error-codes": [
    "missing-input-secret"
  ]
}

I can not find any solution that works, even the official Vapor docs were of no use, could someone please help me?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

As Nick said: the problem was that instead of .formData , I needed to use .urlEncodedForm .

over 4 years ago · Santiago Trujillo Report

0

The Google API requires requests to be URL-encoded forms. By using the .formData setting, you are enforcing MultiPart.

Change the setting to .urlEncodedForm, which ensures the request conforms to the Google API requirement.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!