java - 如何运行单元测试我收到 415 错误,但以正确的格式传递 json?
问题描述
@Test
public void testAuthenticationForSubmitModelingRequest() {
String url = "http://localhost:9081/prop/submitModellingRequest";
String name = "admin";
String password = "admin";
String authString = name + ":" + password;
byte[] authStringEnc = Base64.getEncoder().encode(authString.getBytes());
String input = "{\"modelingVersionID\":\"1007\",\n" +
"\"modelingRequestID\":\"75891\",\n" +
"\"cycleId\":\"20033\",\n" +
" \"imtId\":\"225\",\n" +
" \"submarketID\":\"0\",\n" +
"\"brandSubSubGroupID\":\"11\",\n" +
"\"modelStatus\":null,\n" +
"\"modelingTechStatus\":null,\n" +
"\"requestType\":null,\n" +
"\"targetType\":\"0\",\n" +
"\"targetTypeName\":null,\n" +
"\"serverId\":\"1\"}";
String authStringEnc1 = new String(authStringEnc);
System.out.println("Base64 encoded auth string: " + authStringEnc);
Client restClient = Client.create();
WebResource webResource = restClient.resource(url);
ClientResponse resp = webResource.accept("application/json").header("Authorization", "Basic " + authStringEnc1)
.post(ClientResponse.class,input);
if (resp.getStatus() != 201) {
System.err.println("Unable to connect to the server");
}
String output = resp.getEntity(String.class);
System.out.println("response: " + output);
}
尝试运行单元测试时出现 415 错误,即使以正确的格式传递 json..试图在我的 rest api 上调用 post 方法请帮助
解决方案
推荐阅读
- rust - 如何为特征提供 IntoIterator 的默认实现?
- c# - 在 MEF 中的泛型方法中转换类
- html - 我的浏览器中仍然显示隐藏的列,这是什么问题?
- vue.js - 如何将垂直“b-tabs”导航部分和内容部分的高度设置为相同(基于内容部分)
- function - 在 Go 中是否可以使用命名参数调用函数?
- label - 使用python在Gtk中的标签内垂直居中文本
- wordpress - 我们能否重做一个在 wordpress.org 上发布的插件,并为已在该站点上安装该插件的用户禁用更新
- batch-file - 使用 JQ 在 Windows shell 中通过子元素的内容过滤 JSON 的元素?
- android-studio - 生成签名的 APK - ClassNotFoundException:com.google.wireless.android.sdk.stats.IntellijIndexingStats$Index
- c# - 在标记为 APIController 的控制器上使用分页时返回不支持的媒体类型