LINUX.ORG.RU

Ответ на: комментарий от TERRANZ
@RequestMapping(value = "/login", method = RequestMethod.POST)
    public ResponseEntity<LoginResponse> doLogin(@RequestBody LoginRequest loginRequest) {
        log.debug("doLogin. Login: "+loginRequest.getLogin()+" Password: "+loginRequest.getPassword());
        
        LoginResponse resp = new LoginResponse();
        resp.result = true;
        return new ResponseEntity<LoginResponse>(resp, HttpStatus.OK);
    }

ответ на клиенте

The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ().

И что делать?

bvn13 ★★★★★
() автор топика
Ответ на: комментарий от bvn13
@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE)

Так как-то? produces указать?

BattleCoder ★★★★★
()
Ответ на: комментарий от PolarFox

вот мой тестовый вариант на ангуляре:

$scope.doLogin = function() {
        $log.log("User: "+$scope.user.login+" Password: "+$scope.user.password);
        $http
        .post('login.html', $scope.user)
        .success(function(data, status, headers, config) {
            $log.log("login success");
        })
        .error(function(data, status, headers, config) {
            $log.log("login error");
        });
    };

bvn13 ★★★★★
() автор топика
Ответ на: комментарий от bvn13

Через curl может попробовать для чистоты эксперимента?

curl -XPOST -d <тело запроса> -H 'content-type: application/json' <url>
BattleCoder ★★★★★
()
Ответ на: комментарий от bvn13

пока я со всем эти не разобрался, делал вот так

        @RequestMapping(value = URLConstants.DoJson.Products.PRODUCT_GET_PRODUCT, method = { RequestMethod.GET, RequestMethod.POST })
        private ResponseEntity<String> getProduct(HttpServletRequest request, @RequestParam(required = true, defaultValue = "0") Integer id) {
                ProductDTO ret = new ProductDTO();
                Product p = pe.getBean(id);
                if (p != null)
                        ret = new ProductDTO(p);
                else
                        ret.ok = false;
                return ResponceUtils.makeResponce(new JSONSerializer().deepSerialize(ret));
        }
 

 public static ResponseEntity<String> makeResponce(String json) {
                HttpHeaders headers = new HttpHeaders();
                headers.add("Content-Type", "application/json; charset=utf-8");
                return new ResponseEntity<String>(json, headers, HttpStatus.OK);
        }

а вообще всё это вот тут https://github.com/TERRANZ/market/blob/master/src/main/java/ru/terra/market/c...

TERRANZ ★★★★
()
Ответ на: комментарий от TERRANZ

return ResponceUtils.makeResponce(new JSONSerializer().deepSerialize(ret));

Извините, что придираюсь, но у вас опечатка в слове Responce.

php-coder ★★★★★
()
Ответ на: комментарий от TERRANZ

Да, добавил @ResponseBody, добавил produces, и с клиента запрос к login.json (предварительно добавив обработку этого разширения в web.xml спринга)

bvn13 ★★★★★
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.