大家好,我在休息API中苦苦挣扎,我需要在标题中发布带有标题的XML并获得响应,任何人都可以发布如何做到这一点的示例吗?

时间:2017-02-15 07:28:23

标签: rest api rest-assured web-api-testing

 String reqURL = baseUrl + data_oauth.get(PropLoad.getTestXmlData("URL"));
    Template template = new Template();
    String updatedUrl = template.getUpdatedURL(reqURL);

    Map<String, String> headers = Template.getRequestData(data_oauth,PropLoad.getTestXmlData("HEADER"));
    headers.entrySet().toString();

    String updatedAuthor = template.getAuthorizationHeader(headers, methodDesc);
    headers.put("Authorization", updatedAuthor);
    String xmlRequest = Template.generateStringFromResource(data_oauth,"xmlbody");
    Response response = webCredentials_rest.postCallWithHeaderAndBodyParamForXml(headers, xmlRequest, updatedUrl);

//正在回复Unmarshalled,可以帮助我发布带有XML正文的POST请求吗

1 个答案:

答案 0 :(得分:0)

您可以这样发送:

URL url = new URL(urlString);
URLConnection connenction = url.openConnection();
OutputStream output = connenction.getOutputStream();
InputStream input = new FileInputStream(xmlFile);
byte[] buffer = new byte[4096];
int len;
while ((len = input .read(buffer)) >= 0) {
    out.write(buffer, 0, len);
}
input .close();
output.close();

并阅读这样的回复:

StringBuilder stringBuilder = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(connenction.getInputStream()));
String readLine = reader.readLine();
while (readLine != null) {
    stringBuilder.append(readLine);
    readLine = br.readLine();
}