+ Start a Discussion
subaasubaa 

Need the sample code to set request body for POST method

Hi,

 

Can anyone send me the reference document or sample code (in Java) to set request body values for a POST method?

 

It would be grateful if you send me the code fro this sample data.

 

{

   "body" : {
      "messageSegments" : [
      {
         "type": "mention",
         "id" : "005D0000001GpHp"
      },
      {
         "type": "text",
         "text" : " Did you see the new plans?"
      }
    ]
   }
}

 

Regards,

SuBaa

cloudcodercloudcoder

Here is an example in Ruby. A post is effectively a HTTP POST. The trick is setting up the json response correctly (see the snippet below):

 

def self.set_my_user_status(post)
    options = Chatter.set_http_options
    
    options.merge!( :body => { :body => { :messageSegments => [
                                {
                                  :type => "Text",
                                  :text => post.body
                                }
                              ]}
                             }.to_json
                    )
   puts @options
    @response = HTTParty.post(Chatter.root_url+"/feeds/news/me/feed-items", options)
    end