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

  • Home
  • SEARCH
  • 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 1099329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:43:12+00:00 2026-05-17T00:43:12+00:00

I need to post some xml to a webservice and I’m trying to use

  • 0

I need to post some xml to a webservice and I’m trying to use HTTParty. Can someone provide an example as to how I go about doing so?

Here is the format of the XML I need to post:

<Candidate xmlns="com.mysite/2010/10/10" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<FirstName></FirstName>
<LastName></LastName>
<Email></Email>
<Gender></Gender>
</Candidate>

Here is my class so far:

require 'httparty'


class Webservice
  include HTTParty
  format :xml
  base_uri 'mysite.com'
  default_params :authorization => 'xxxxxxx'

  def self.add_candidate(first_name,last_name,email,gender)
    post('/test.xml', :body => "")    
  end  
end

I’m not quite sure how to flesh out add_candidate.

Any help would be appreciated.

Thanks.

  • 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-17T00:43:12+00:00Added an answer on May 17, 2026 at 12:43 am

    You’ve got two options. HTTParty allows you to post both a string or a hash.

    The string version would be:

    post('/test.xml', :body => "<Candidate xmlns=\"com.mysite/2010/10/10\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><FirstName>#{first_name}</FirstName><LastName>#{last_name}</LastName><Email>#{email}</Email><Gender>#{gender}</Gender></Candidate>")
    

    Functional, but not pretty. I’d do this instead:

    post('/test.xml', :body => {
      :Candidate => {
        :FirstName => first_name,
        :LastName  => last_name,
        :Email     => email,
        :Gender    => gender,
      }
    }
    

    Now, I can’t say for sure whether the namespaces are required by the endpoint, and if so, whether the hash version will work. If that’s the case, you may have to go with doing the body as a string.

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

Sidebar

Related Questions

I would like to invoke a webservice via Android. I need to POST some
I have to make a HTTPS Post with some XML data, but I need
I need to POST some XML data to a remote server for processing. The
I need to post some text to a remote server over HTTP, this server
I need to capture the HTML and do some post processing on the HTML
I'm running a Tomcat server with some virtual hosts and I need to POST
I recently created a post about flattening an XML structure so every element and
I need some help posting some XML to a WCF service. In essence, the
I need to send some post data to another server in mule 3.1.2. Here
I use: wget --no-check-certificate --http-user=user --http-password=secret --header=Content-Type:text/xml --post-file=request.xml https://mydominain.com/xml to send an xml request.

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.