无法发送带有androidannotations的POST参数

玩具玩具

因此,我试图使用androidannotation从Android应用程序向我的REST服务器发送一个简单的String。

http://localhost:8080/TestServer_RESTJersey/api/lanceurs/parPays

使用Advanced REST client chrome扩展,我发送参数:

country=Europe

并且工作正常。现在,我遇到的问题是,Android应用程序是服务器收到了我的请求,但是country参数始终为null。我的其他GET请求都运行良好。

这是我的RestClient类:

@Rest(converters = {MappingJacksonHttpMessageConverter.class, FormHttpMessageConverter.class})
    public interface RestClient extends RestClientRootUrl, RestClientSupport{

        @Get("/poke/simple")
        public MessageResponse simplePoke();

        @Get("/api/lanceurs/{name}")
        public LaunchVehicleResponse nameRequest(String name);

        //server doesn't get the parameter here...
        @Post("/api/lanceurs/parPays")
        public LaunchVehicleResponse countryRequest(String country);        
    }

任何帮助将不胜感激,谢谢!

编辑 :

服务器端REST api:

@Path("api/lanceurs/parPays")
    @POST
    public String getLanceurByCountry(@FormParam("country") String country)
    {
        initData();
        LaunchVehicleResponse lvr = new LaunchVehicleResponse();
        ArrayList<LaunchVehicle> allv = myDatabase.getDataByCountry(country);
        lvr.setData(allv);
        return parseObjectToJson(lvr);
    }
玩具玩具

好的,看来我想出了一种摆脱困境的方法。

我在客户端上创建了一个LaunchVehicleRequest类,其中(其中包括)一个国家/地区字符串。当我需要向服务器发送请求时,我将实例化该类,并使用所需的值(例如:“ USA”)初始化LaunchVehicleRequest.country。然后,将整个对象发送到我的RestClient。

LaunchVehicleRequest lvreq = new LaunchVehicleRequest();
lvreq.setCountry("Europe");
LaunchVehicleResponse lvr = pm.countryRequest(lvreq);

...

    @Rest(converters = {MappingJacksonHttpMessageConverter.class, FormHttpMessageConverter.class}, interceptors = { LoggingInterceptor.class } )
    public interface RestClient extends RestClientRootUrl, RestClientSupport, RestClientHeaders{
        @Post("/api/lanceurs/parPays")
        public LaunchVehicleResponse countryRequest(LaunchVehicleRequest request);
}

我在服务器端设置了相同的类,该类将请求作为字符串获取,然后将其转换为对象。

@Path("api/lanceurs/parPays")
@POST
public String getLanceurByCountry(String request)
{
    //  request={"country":"USA"}       
    //my json parsing function here
    LaunchVehicleRequest lvreq = parseJsonToRequest(request);
    ...
}

我不知道这是最好的方法,但是嘿,它现在工作正常,我正在对需要的每个不同请求使用我的LaunchVehicleRequest类,所以我猜这还不错吧^^'

还是谢谢大家;)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法发送带有正文的 POST

ios发送带有POST参数的POST请求

如何在带有多个参数的angularjs中发送POST?

发送带有参数的 post 请求时脚本卡住

带有axios的POST请求未发送参数

如何在 AngularJS 中发送带有多个参数的 POST

$ .fileDownload库无法正确发送带有“ POST”的数组

使用 J Meter 使用 Web-kit Form-Data 发送带有 POST 请求的参数

在Python中,如何发送带有5个嵌套深的URL编码参数的POST请求?

如何通过带有标题中的自定义参数的RestTemplate发送POST请求

如何使用cURL发送带有请求参数的POST请求?

如何在带有多个参数的angular5中发送POST?

ios-通过POST方法发送带有其他参数的图像

如何使用cURL发送带有正文,标头和HTTP参数的POST?

带有Spring Rest模板的AndroidAnnotations混淆后无法正常工作

Livecode“发送”带有引号的参数

javascript发送带有文件的发布参数

发送带有特定参数的图片?

React-无法发送带有额外参数的redux-thunk操作

为什么ng-click无法发送带有大括号{{}}的函数参数?

无法将带有 GM_xmlhttpRequest 的数据从带有 POST 方法的 Tampermonkey 发送到 Scalatra

Python发送带有标头的POST

FB API发送带有图像的POST

使用带有HttpURLConnection的POST发送文件

AngularJS:无法发送带有适当的CORS标头的POST请求

PHP curl没有发送post参数

带有 Firebase 的 Angularjs 无法发送数据

无法将带有jquery的参数从正文传递到webapi post方法

Django:返回带有POST参数的模板