测试一个接口,在postman里很容易就通过。其中body部分需要上传的参数是这样的
对应的程序里我是通过创建两个json实现的
import net.sf.json.JSONObject;
String sourceBody = new StringBuilder()
.append("{\"href\":\""+ fromFoundingSource +"\"}")
.toString();
String destinationBody = new StringBuilder()
.append("{\"href\":\""+ toFoundingSource +"\"}")
.toString();
String amountBody = new StringBuilder()
.append("{\"currency\":\""+ currency +"\",")
.append("\"value\":\""+ money +"\"}")
.toString();
JSONObject linksJson = new JSONObject();
linksJson.put("source", sourceBody);
linksJson.put("destination", destinationBody);
JSONObject json = new JSONObject();
json.put("_links", linksJson.toString());
json.put("amount", amountBody);
最后将把json作为body参数设置到请求中,完成。