错误的URI(不是URI?):{“message”:“d64”,“type”:“success”}

时间:2015-06-04 11:39:29

标签: ruby-on-rails api httprequest httpresponse httparty

我使用httparty发送API请求,我希望在发送请求后获得输出响应,

url = HTTParty.post("https://example.com/api/sendhttp.php",
                        :query => { :authkey => "authkeyvalue",
                                    :mobiles => mobileNos,
                                    :message => messages,
                                    :sender => "senderid",
                                    :route => "routeid",
                                    :response => 'json'
                                   })

    response = HTTParty.get(url)
    puts response.body, response.code, response.message, response.headers.inspect

但是当我在代码上面运行时会抛出错误的URI(is not URI?): {"message":"d64","type":"success"}错误。如何解决并得到回应?

1 个答案:

答案 0 :(得分:1)

这看起来你正在使用JSON格式运行https://example.com/api/sendhttp.php的POST,这成功了,你得到的回复是:

{"message":"d64","type":"success"}

因此,您的url变量现在包含{"message":"d64","type":"success"},这显然不是有效的网址,因此当您尝试对其执行GET时,会出现错误。你已经得到了第一个POST的响应,你应该解析一下吗?你不需要做

response = HTTPParty.get(url)

除非您期望对第一个返回的URL发出第二个GET请求。