0

我正在尝试编写一些代码来从涟漪 API ( https://ripple.com/wiki/JSON_Messages ) 中检索我的帐户状态。我目前使用的代码:

    #require "netclient";;
    open Http_client.Convenience;;

    let account_info =
      [
        ("command","account_info");
        ("account","my_account_key")
      ]
    ;;

    let response = http_post_message "http://s1.ripple.com:51234" account_info;;

我将请求发送到http://s1.ripple.com:51234并且收到错误请求错误。注意:我已经尝试了方法和命令作为参数以及 http_post 和 http_post_message 方法。

    # response#status;;
    - : Http_client.status = `Client_error
    # response#response_status;;
    - : Nethttp.http_status = `Bad_request

我在请求数据的方式上肯定做错了什么,但我在这个主题方面没有足够的经验来知道我哪里出错了。我想也许我应该使用 Http_client.post_raw 方法,但是我的顶层无法识别这个方法。我不确定如何继续纠正我的错误。

    # Http_client.post_raw;;
    Error: Unbound value Http_client.post_raw        

提前致谢。

4

2 回答 2

3

使用 HTTP API 时,首先使用 curl 命令行实用程序测试 API。一旦您得到预期的响应 - 实现代码以发送具有相同标头的相同请求。检查curl -vhttp 库的调试工具。

于 2013-11-25T07:49:24.127 回答
1

您的服务器可能有问题:

$ curl -v http://s1.ripple.com:51234/
* About to connect() to s1.ripple.com port 51234 (#0)
*   Trying 54.200.86.207...
* Adding handle: conn: 0x7f92a1808c00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7f92a1808c00) send_pipe: 1, recv_pipe: 0
* Connected to s1.ripple.com (54.200.86.207) port 51234 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.32.0
> Host: s1.ripple.com:51234
> Accept: */*
>
* Empty reply from server
* Connection #0 to host s1.ripple.com left intact
curl: (52) Empty reply from server

我经常使用 OcamlNet,如果我可以建议您:之前在终端中使用 curl 测试您的 url。

于 2013-11-25T10:02:07.017 回答