传出POST请求的Retrofit Log与传入数据包不匹配

时间:2014-04-16 06:20:30

标签: java django post retrofit

我正在尝试通过Retrofit向我的远程Django服务器发送POST请求。我已经为RestAdapter for Retrofit创建了一个日志,但是当我监控日志时,我注意到请求正在以POST方式正确发送:

---> HTTP POST http://[omitted IP]/users/login_user/?username=Lucas&platform=AND&client_version=1.0
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 18

password=abcd12345
---> END HTTP (18-byte body)

但它在服务器上接收(根据tcpdump)作为GET请求。

我可以使用curl发送基本相同的请求:

curl -X POST -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -d 'password=abcd12345' "http://[omitted IP]:22800/users/login_user/?username=Lucas&platform=AND&client_version=1.0"

,这会导致服务器收到POST请求,并正确处理。

以下是tcpdump通过curl发布的POST数据包:

05:54:25.849761 IP [omitted IP].dsl.teksavvy.com.53549 > 192.168.0.150.22080: Flags [P.], seq 1:251, ack 1, win 229, options [nop,nop,TS val 9311380 ecr 191199659], length 250
 E...;.@.8.cQE........-V@a./.........f9.....
 .....ey.POST /users/login_user/?username=Lucas&platform=AND&client_version=1.0 HTTP/1.1
 User-Agent: curl/7.32.0
 Host: [omitted IP]:22800
 Accept: */*
 Content-Type: application/x-www-form-urlencoded; charset=UTF-8
 Content-Length: 18

 password=abcd12345

我认为应该是来自tcpdump通过Retrofit的相同数据包(但不是):

05:57:40.801738 IP [omitted IP].dsl.teksavvy.com.55429 > 192.168.0.150.22080: Flags [P.], seq 1:320, ack 1, win 229, options [nop,nop,TS val 45578792 ecr 191219119], length 319
E..s.g@.8...E.........V@.h...........i.....
..z(.e..GET /users/login_user/?username=Lucas&platform=AND&client_version=1.0 HTTP/1.1
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.2.1; Galaxy Nexus Build/JOP40D)
Host: [omitted IP]:22800
Connection: Keep-Alive
Accept-Encoding: gzip
Content-Length: 18

数据包可以在哪里更改?数据包是否在应用层可能被修改后记录在tcpdump中?或者Retrofit撒谎并实际发送GET请求?有关如何进一步调试此问题的任何想法将不胜感激。

1 个答案:

答案 0 :(得分:0)

我通过将端点网址从:endpoint-address.com更改为www.endpoint-address.com来解决了问题。这就是服务器从无www地址重定向似乎搞砸了POST请求。

相关问题