使用HTTParty记录用户

问题描述 投票:0回答:1

我有一个shi ** y API,它在使用HTTParty的GET请求之后返回一个损坏的JSON。

GET HTTParty.get('url/login/success/', headers: {cookie: "JSESSIONID=ID"})返回JSON::ParserError (765: unexpected token at)

和response.body是

"{\"head\":{\"apikey\":null,\"sessionid\":\"ID\",\"timestamp\":1551772335837,\"sessiontimeout\":1551775035837,\"wishlistItemsCount\":0,\"basketItemsCount\":0,\"loggedIn\":true,\"role\":\"C\"},\"data\":{\"user\":{\"profile\":{\"title\":\"Title\",\"firstname\":\"Name\",\"lastname\":\"Lastname\",\"street\":\"Street\",\"street2\":\"number\",\"postalcode\":\"code\",\"city\":\"City\",\"customerID\":\"ID\",\"customerType\":xx}},\"abandonedBasket\":false},\"messages\":[{\"code\":\"url.api.login.success\",\"statusCode\":200,\"description\":\"OK\"}]}{\"head\":{\"apikey\":null,\"sessionid\":\"ID\",\"timestamp\":1551772335841,\"sessiontimeout\":1551775035841,\"wishlistItemsCount\":0,\"basketItemsCount\":0,\"loggedIn\":true,\"role\":\"C\"},\"data\":{},\"messages\":[{\"code\":\"url.api.general.error\",\"statusCode\":500,\"description\":\"Es ist ein interner Fehler aufgetreten. Bitte versuchen sie es später noch einmal.\"}]}"

有没有可能修复响应的JSON供用户登录并正常使用他的帐户?

我有的替代方法是在代码中使用curl,但我想避免它

ruby-on-rails authentication httparty
1个回答
0
投票

可能你没有发送JSON数据。

检查这个Changing Content-Type to JSON using HTTParty

  1. 内容类型
  2. to_json
© www.soinside.com 2019 - 2024. All rights reserved.