我在服务器上有一个烧瓶app和api,它使用从终端发送的以下url
curl -i -H "Content-type: application/json" -X GET http://myapp.com/890/14000/10000/007 -d '{"id":"3240f056c8f5fb"}'
我试图在Android上使用改造来重新创建它.我使用的是1.7版,因为这适用于此处未显示的一些遗留代码.这是应用程序类的相关部分
DavesApi buildDavesApi() { Gson gson = new GsonBuilder() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERscoreS) .create(); return new RestAdapter.Builder() .setLogLevel(RestAdapter.LogLevel.FULL) // change this to FULL to see full JSON response .setEndpoint(DAVESENDPOINT) .setConverter(new GsonConverter(gson)) .setRequestInterceptor(new RequestInterceptor() { @Override public void intercept(RequestFacade request) { request.addHeader("Content-type","application/json"); } }) .build() .create(DavesApi.class); }
和api类
public interface DavesApi { @Headers("\{\"id\"\:\"3240f056c8f5fb\"\}") @GET("/{importantnumber}/14000/10000/007") void getThumbnail(@Path("importantnumber") Integer id,Callback<DavesActivity> activity); }
我现在只得到一般性错误,例如
D/Retrofit: ---> HTTP GET http://myurl.com/420059/14000/10000/007 D/Retrofit: '{"id": "3240f056c8f5fb"}' D/Retrofit: Content-Type: application/json D/Retrofit: ---> END HTTP (no body) D/Retrofit: <--- HTTP 400 http://myurl.com/420059/14000/10000/007 (2653ms) D/Retrofit: : HTTP/1.1 400 BAD REQUEST D/Retrofit: Connection: keep-alive D/Retrofit: Content-Length: 95 D/Retrofit: Content-Type: application/json D/Retrofit: Date: Sun,29 Nov 2015 23:08:45 GMT D/Retrofit: Server: ngx_openresty/1.4.3.6 D/Retrofit: X-Android-Received-Millis: 1448838524561 D/Retrofit: X-Android-Response-Source: NETWORK 400 D/Retrofit: X-Android-Sent-Millis: 1448838523377 D/Retrofit: {"description": "The browser (or proxy) sent a request that this server could not understand."} D/Retrofit: <--- END HTTP (95-byte body) E/activity_fragment: retrofit.RetrofitError: 400 BAD REQUEST
这是我的第一个烧瓶应用程序,我不完全确定如何调试所以任何帮助在这里也是赞赏.
我也没有访问服务器日志
更新
为了尝试追踪问题,我编辑了服务器上的代码.如果我只是在api中返回一个字符串,那么改造就会收到响应.如果我尝试从改造中返回标头中发送的任何数据,我会得到一个空的响应,而curl请求将得到相应的响应.我已经尝试使用response.data和response.json来确保它不仅仅是一个json编码问题.但是,在执行此操作时,我需要删除“Content-type”,“application / json”标题,以便不能获得之前发布的400.
返回response.data时的新日志
D/Retrofit: ---> HTTP GET http://myurl.com/420059/14000/10000/007 D/Retrofit: test: header D/Retrofit: ---> END HTTP (no body) D/Retrofit: <--- HTTP 200 http://myurl.com/420059/14000/10000/007 (316ms) D/Retrofit: : HTTP/1.1 200 OK D/Retrofit: Connection: keep-alive D/Retrofit: Content-Length: 0 D/Retrofit: Content-Type: text/html; charset=utf-8 D/Retrofit: Date: Mon,30 Nov 2015 20:34:54 GMT D/Retrofit: Server: ngx_openresty/1.4.3.6 D/Retrofit: X-Android-Received-Millis: 1448915692589 D/Retrofit: X-Android-Response-Source: NETWORK 200 D/Retrofit: X-Android-Sent-Millis: 1448915692449 D/Retrofit: X-Clacks-Overhead: GNU Terry Pratchett D/Retrofit: <--- END HTTP (0-byte body) // empty body :(