Rebooting
Rebooting

Reputation: 2938

POST: sending a post request in a url itself

I have been given a url .. www.abc.com/details and asked to send my name and phone number on this url using POST. They have told me to set the content-type as application/json and the body as valid JSON with the following keys:

name: name of the user
phone number: phone number of the user

Now i have no clue how to send this request! Will it be something like:

http://www.abc.com/details?method=post&name=john&phonenumber=445566

or do i have to use java to send the same?

Please help

Upvotes: 42

Views: 353184

Answers (7)

Joshua
Joshua

Reputation: 8212

Based on what you provided, it is pretty simple for what you need to do and you even have a number of ways to go about doing it. You'll need something that'll let you post a body with your request. Almost any programming language can do this as well as command line tools like cURL.

Once you have your tool decided, you'll need to create your JSON body and submit it to the server.

An example using cURL would be (all in one line, minus the \ at the end of the first line):

curl -v -H "Content-Type: application/json" -X POST \
     -d '{"name":"your name","phonenumber":"111-111"}' http://www.example.com/details

The above command will create a request that should look like the following:

POST /details HTTP/1.1
Host: www.example.com
Content-Type: application/json
Content-Length: 44

{"name":"your name","phonenumber":"111-111"}

Upvotes: 52

Brindha
Brindha

Reputation: 349

It is not possible to send POST parameters in the URL in a straightforward manner. POST request in itself means sending information in the body.

I found a fairly simple way to do this. Use Postman by Google, which allows you to specify the content-type (a header field) as application/json and then provide name-value pairs as parameters.

You can find clear directions at [2020-09-04: broken link - see comment] http://docs.brightcove.com/en/video-cloud/player-management/guides/postman.html

Just use your URL in the place of theirs.

Upvotes: 5

rohan
rohan

Reputation: 151

If you are sending a request through url from browser(like consuming webservice) without using html pages by default it will be GET because GET has/needs no body. if you want to make url as POST you need html/jsp pages and you have to mention in form tag as "method=post" beacause post will have body and data will be transferred in that body for security reasons. So you need a medium (like html page) to make a POST request. You cannot make an URL as POST manually unless you specify it as POST through some medium. For example in URL (http://example.com/details?name=john&phonenumber=445566)you have attached data(name, phone number) so server will identify it as a GET data because server is receiving data is through URL but not inside a request body

Upvotes: 2

Richa Agrawal
Richa Agrawal

Reputation: 21

You can use postman.

Where select Post as method. and In Request Body send JSON Object.

Upvotes: 2

Sir l33tname
Sir l33tname

Reputation: 4330

You can post data to a url with JavaScript & Jquery something like that:

$.post("www.abc.com/details", {
    json_string: JSON.stringify({name:"John", phone number:"+410000000"})
});

Upvotes: 8

Jayani Sumudini
Jayani Sumudini

Reputation: 1509

In windows this command does not work for me..I have tried the following command and it works..using this command I created session in couchdb sync gate way for the specific user...

curl -v -H "Content-Type: application/json" -X POST -d "{ \"name\": \"abc\",\"password\": \"abc123\" }" http://localhost:4984/todo/_session

Upvotes: 1

JDGuide
JDGuide

Reputation: 6525

In Java you can use GET which shows requested data on URL.But POST method cannot , because POST has body but GET donot have body.

Upvotes: -4

Related Questions