简体   繁体   English

如何通过JSON发送带有多个参数的http请求

[英]How to send put http request with multiple parameters through JSON

I have the list of students with id , firstName , lastName and email , and I have put http method that has two arguments, id and student which finds the student with given id and replace that student whit new one (second parameter). 我有idfirstNamelastNameemail的学生列表,我已经put http方法有两个参数, idstudent ,找到给定id的学生,并替换那个学生新的一个(第二个参数)。

I have to send that put http request as JSON , but I don't know how to write that request properly. 我必须发送put http请求作为JSON发送,但我不知道如何正确编写该请求。 This is what I tried: 这是我试过的:

{
    "id": 8,
    "firstName": "aaaa",
    "lastName": "aaaa",
    "email": "aaaa"
},
{
"id: 2"
}

So the student with id = 2 should be replaced with the student above. 所以id = 2的学生应该替换为上面的学生。 Basically I have trouble making this request with two parameters. 基本上我无法使用两个参数发出此请求。

include the id of the student you want to replace on the url. 在网址上包含您要替换的学生的ID。 Something like: 就像是:

server:port/yourapp/student/2 服务器:端口/ yourapp /学生/ 2

Use the body only for the data related to the student you want to write in the db. 仅将主体用于与要在db中写入的学生相关的数据。

However, changing an id doesn't seem very restful. 但是,更改ID似乎不太安宁。

You can create a custom object model that will hold a student and an additional parameter (id of another student): 您可以创建一个自定义对象模型来保存student和另一个参数(另一个学生的ID):

{
    "student":
    {
        "id": 8,
        "firstName": "aaaa",
        "lastName": "aaaa",
        "email": "aaaa"
    },
    "studentId": 2
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM