POST: sending a post request in a url itself

前端 未结 7 1209
忘掉有多难
忘掉有多难 2020-12-24 12:46

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 cont

相关标签:
7条回答
  • 2020-12-24 12:49

    It is not possible to send POST parameters in the url in a starightforward 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.

    Hope it helps

    0 讨论(0)
  • 2020-12-24 12:51

    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.

    0 讨论(0)
  • 2020-12-24 12:54

    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

    0 讨论(0)
  • 2020-12-24 12:57

    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"})
    });
    
    0 讨论(0)
  • 2020-12-24 13:01

    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"}
    
    0 讨论(0)
  • 2020-12-24 13:09

    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
    
    0 讨论(0)
提交回复
热议问题