---
title: "erlang rest api 调试信鸽"
author: "夏日春天"
date: "2015-01-26T18:06:45Z"
tags: []
categories: ["开源软件"]
slug: "erlang-rest-api"
draft: false
lastmod: "2015-01-26T18:06:45Z"
id: 2180189
url: "https://david-erl.iteye.com/blog/2180189"
---

困扰了两天的问题，今天终于搞定了，这里要感谢下信鸽后端开发的哥们,废话就不多说了，直接上主题：

 在发送POST请求到信鸽服务器时总是返回"invalid sign"  通过与Java代码校对，参数和sign都已经完全一致了，可java就可以成功，唯独erlang的request请求失败，返回-3 ，中间去看好久没看的java代码的痛苦就不多说了 。

 

今天通过抓包软件，截获两个请求的包信息，信息如下：

——erlang  headers-------

POST /v2/push/all\_device HTTP/1.1

content-type: application/x-www-form-urlencoded; boundary=----WebKitFormBoundarySy4dtGDHm71EqrZI

content-length: 95

user-agent: Erlang Cowboy

te:

host: [openapi.xg.qq.com](http://openapi.xg.qq.com)

accept: text/html, image/gif, image/jpeg, \*; q=.2, \*/\*; q=.2

pragma: no-cache

connection: keep-alive

cache-control: no-cache

sign=71c6d3a9408b97b0af08b0277b1aa07f&timestamp=1422251609&access\_id=2100080448&valid\_time=600&

result： {\\"ret\_code\\":-3,\\"err\_msg\\":\\"invalid sign\\"}"}

 

———java  hesders——-----

POST /v2/push/all\_device HTTP/1.1

Content-Type: application/x-www-form-urlencoded; boundary=----WebKitFormBoundarySy4dtGDHm71EqrZI

Cache-Control: no-cache

Pragma: no-cache

User-Agent: Java/1.6.0\_65

Host: [openapi.xg.qq.com](http://openapi.xg.qq.com)

Accept: text/html, image/gif, image/jpeg, \*; q=.2, \*/\*; q=.2

Connection: keep-alive

Content-Length: 95

sign=71c6d3a9408b97b0af08b0277b1aa07f&timestamp=1422251609&valid\_time=600&access\_id=2100080448&

result:   {"err\_msg":"param message\_type error!","ret\_code":-1}

最后发现erlang的请求中多了个"te",可这又是底层封装好的，没办法去掉，我就赋个值，结果成功了，最后问题锁定在了header中的te未赋值的原因。

后来测试我在java中也添加te，也不赋值  java反而不会有影响，很奇怪的问题。

添加个链接，里面有详细讲解header中te的部分，英文好的可以看一看，记得要分享心得哈。

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

好了不多说了，开始封装推送。完事共享到github上.