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
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. Just use your URL in the place of theirs.
In computing, POST is a request method supported by HTTP used by the World Wide Web. By design, the POST request method requests that a web server accept the data enclosed in the body of the request message, most likely for storing it. It is often used when uploading a file or when submitting a completed web form.
Short answer: in POST requests, values are sent in the "body" of the request. With web-forms they are most likely sent with a media type of application/x-www-form-urlencoded or multipart/form-data .
To post HTML form data to the server in URL-encoded format, you need to make an HTTP POST request to the server and provide the HTML form data in the body of the POST message. You also need to specify the data type using the Content-Type: application/x-www-form-urlencoded request header.
The post () method sends a POST request to the specified url. The post () method is used when you want to send some data to the server.
The HTTP POST request method is used to send data to the server or create or update a resource. The POST request is usually used when submitting an HTML form or when uploading data to a server. The HTTP POST request may or may not contain data. Data sent to the server with POST requests are passed in the body of the request message.
After processing the client's POST request, the server returns a response to the browser and indicates whether the server accepts or rejects the document, with a response status code and message. What is the HTTP POST request method used for? The HTTP POST request method is used to send data to the server or create or update a resource.
Below is an example of an HTTP POST request to send JSON data to the server. The size and data type for HTTP POST requests is not limited. But you must specify the data type in the Content-Type header and the data size in the Content-Length header fields. The HTTP POST requests can also send data to the server using the URL parameters.
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.
One 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.abc.com/details
The above command will create a request that should look like the following:
POST /details HTTP/1.1 Host: www.abc.com Content-Type: application/json Content-Length: 44 {"name":"your name","phonenumber":"111-111"}
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"}) });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With