Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Playframework 播放框架放置请求失败_Playframework_Playframework 2.0_Integration Testing_Functional Testing_Put - Fatal编程技术网

Playframework 播放框架放置请求失败

Playframework 播放框架放置请求失败,playframework,playframework-2.0,integration-testing,functional-testing,put,Playframework,Playframework 2.0,Integration Testing,Functional Testing,Put,我正在使用PlayFramework2.2.3创建RESTfulAPI,在测试中遇到了一些问题 我正在运行一个TestServer来测试所有路由。我怀疑这是一个奇怪的问题。所有将JSON有效负载放入路由的PUT请求总是失败 FakeRequest fakeRequest = new FakeRequest(httpMethod, route); if (jsonBody != null) { fakeRequest.withJsonBody(jsonBody); } Result r

我正在使用PlayFramework2.2.3创建RESTfulAPI,在测试中遇到了一些问题

我正在运行一个
TestServer
来测试所有路由。我怀疑这是一个奇怪的问题。所有将JSON有效负载放入路由的PUT请求总是失败

FakeRequest fakeRequest = new FakeRequest(httpMethod, route);

if (jsonBody != null) {
    fakeRequest.withJsonBody(jsonBody);
}

Result result = route(fakeRequest); // <== result is 'null' for PUT with JSON body
assertEquals(status, status(result));
FakeRequest FakeRequest=新的FakeRequest(httpMethod,route);
if(jsonBody!=null){
带jsonBody的伪造请求(jsonBody);
}

结果=路线(fakeRequest);// 这个问题很久以前被问过,但我最近遇到了完全相同的问题

使用jsonbody(JsValue-json)的方法会自动将http方法设置为POST。要克服这个问题,您只需添加http方法作为第二个参数

在您的示例中,它如下所示:

FakeRequest fakeRequest = new FakeRequest(httpMethod, route);

if (jsonBody != null) {
    fakeRequest.withJsonBody(jsonBody, httpMethod);
}

Result result = route(fakeRequest); // <== result should now work for PUT with JSON body
assertEquals(status, status(result));
FakeRequest FakeRequest=新的FakeRequest(httpMethod,route);
if(jsonBody!=null){
用jsonBody伪造请求(jsonBody,httpMethod);
}

结果=路线(fakeRequest);//你说得对,很久以前我就用同样的方法修好了:)谢谢你的回答。