简体   繁体   English

如何测试在自定义对象中发送数据的POST Web服务调用?

[英]How to test POST web service call that send data in Custom Object?

I am using Retrofit for REST API calls. 我正在使用Retrofit进行REST API调用。 I want to check some APIs in Postman but some Web service APIs send input data in Custom Object form.Unable to find how to test it in Postman or online . 我想检查Postman一些API,但是某些Web服务API以“自定义对象”形式发送输入数据。找不到在Postman或在线中进行测试的方法。

Example : 范例:

@POST("/InsertBusinessInfo")
Call<Boolean> postBusinessInfo(@Body BusinessInfo businessRequest);

This BusinessInfo pojo class with some params with get/set methods BusinessInfo pojo类带有一些具有get / set方法的参数

public class BusinessInfo {

    public String getFirstName() {
        return FirstName;
    }

    public void setFirstName(String firstName) {
        FirstName = firstName;
    }

    public String getLastName() {
        return LastName;
    }

    public void setLastName(String lastName) {
        LastName = lastName;
    }
}

How to test this in Postman . 如何在Postman对此进行测试。 Is it the same as 1 by 1 params inserted in Body? 它与在Body中插入的1 x 1参数相同吗? Can anyone explain it? 有人可以解释吗?

Yes it should be simple: 是的,它应该很简单:

In postman add the POST endpoint (eg myBaseUrl/InsertBusinessInfo/) 在邮递员中添加POST端点(例如myBaseUrl / InsertBusinessInfo /)

Then with POST selected, in the Body select form encoding (eg x-www-form-urlencoded). 然后选择POST,在“正文”中选择表单编码(例如x-www-form-urlencoded)。

Now add your POJO field name as 'key' and your field value as 'value'. 现在,将您的POJO字段名称添加为“键”,并将字段值添加为“值”。

This should then POST to your endpoint. 然后应该将其发布到您的端点。

In Postman open a request and from tabs below URL Select Body 在邮递员中打开一个请求,然后从URL下的选项卡中选择正文

from the options below select raw 从以下选项中选择原始

Now mostly the object is serialized in to JSON, so get a JSON for your object 现在大多数对象都序列化为JSON,因此为您的对象获取JSON

{"FirstName":"name...", "LastName":"name2..." ...}

(filled with data) and paste it in the large text area below and click send (充满数据)并将其粘贴到下面的大文本区域中,然后单击发送

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

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