【问题标题】:Titanium HTTPClient doesn't return the full responseTitanium HTTPClient 不返回完整响应
【发布时间】:2017-01-20 17:16:58
【问题描述】:

我对 Appcelerator Titanium 中的HTTPClient 有疑问。 我将它用于对以下端点的 GET 请求:

https://rxnav.nlm.nih.gov/REST/interaction/list.json?rxcuis=5640+53694

它应该返回这样的响应:

{  
   "nlmDisclaimer":"It is not the intention of NLM to provide specific medical advice, but rather to provide users with information to better understand their health and their medications. NLM urges you to consult with a qualified physician for advice about medications.",
   "userInput":{  
      "sources":[  
         ""
      ],
      "rxcuis":[  
         "5640",
         "53694"
      ]
   },
   "fullInteractionTypeGroup":[  
      {  
         "sourceDisclaimer":"DrugBank is intended for educational and scientific research purposes only and you expressly acknowledge and agree that use of DrugBank is at your sole risk. The accuracy of DrugBank information is not guaranteed and reliance on DrugBank shall be at your sole risk. DrugBank is not intended as a substitute for professional medical advice, diagnosis or treatment..[www.drugbank.ca]",
         "sourceName":"DrugBank",
         "fullInteractionType":[  
            {  
               "comment":"Drug1 (rxcui = 53694, name = nimesulide, tty = IN). Drug2 (rxcui = 5640, name = Ibuprofen, tty = IN). Drug1 is resolved to nimesulide, Drug2 is resolved to Ibuprofen and interaction asserted in DrugBank between Nimesulide and Ibuprofen.",
               "minConcept":[  
                  {  
                     "rxcui":"53694",
                     "name":"nimesulide",
                     "tty":"IN"
                  },
                  {  
                     "rxcui":"5640",
                     "name":"Ibuprofen",
                     "tty":"IN"
                  }
               ],
               "interactionPair":[  
                  {  
                     "interactionConcept":[  
                        {  
                           "minConceptItem":{  
                              "rxcui":"53694",
                              "name":"nimesulide",
                              "tty":"IN"
                           },
                           "sourceConceptItem":{  
                              "id":"DB04743",
                              "name":"Nimesulide",
                              "url":"http://www.drugbank.ca/drugs/DB04743#interactions"
                           }
                        },
                        {  
                           "minConceptItem":{  
                              "rxcui":"5640",
                              "name":"Ibuprofen",
                              "tty":"IN"
                           },
                           "sourceConceptItem":{  
                              "id":"DB01050",
                              "name":"Ibuprofen",
                              "url":"http://www.drugbank.ca/drugs/DB01050#interactions"
                           }
                        }
                     ],
                     "severity":"N/A",
                     "description":"The risk or severity of adverse effects can be increased when Ibuprofen is combined with Nimesulide."
                  }
               ]
            }
         ]
      }
   ]
}

使用钛 HTTPClient 我得到的只是这个响应:

{  
   "nlmDisclaimer":"It is not the intention of NLM to provide specific medical advice, but rather to provide users with information to better understand their health and their medications. NLM urges you to consult with a qualified physician for advice about medications.",
   "userInput":{  
      "sources":[  
         ""
      ],
      "rxcuis":[  
         "5640+53694"
      ]
   }
}

发出请求的代码如下:

var client = Ti.Network.createHTTPClient({

        onload: function() {
            console.log(this.responseText);
            var json = JSON.parse(this.responseText);
            console.log(json);
        },

        onerror: function() {
            console.log(this.responseText);
        }

    });

    var url = "https://rxnav.nlm.nih.gov/REST/interaction/list.json?rxcuis=5640+53694";
    client.open("GET", url);
    client.setRequestHeader("Accept", "application/json");
    client.send();

我也尝试返回 xml 而不是 json,但它是一样的,只返回响应的第一部分。有关如何解决此问题的任何线索?

【问题讨论】:

    标签: json get httpclient response appcelerator-titanium


    【解决方案1】:

    我刚刚运行了您的代码,似乎对我来说工作正常:

    [INFO]  {"nlmDisclaimer":"It is not the intention of NLM to provide specific medical advice, but rather to provide users with information to better understand their health and their medications. NLM urges you to consult with a qualified physician for advice about medications.","userInput":{"sources":[""],"rxcuis":["5640","53694"]},"fullInteractionTypeGroup":[{"sourceDisclaimer":"DrugBank is intended for educational and scientific research purposes only and you expressly acknowledge and agree that use of DrugBank is at your sole risk. The accuracy of DrugBank information is not guaranteed and reliance on DrugBank shall be at your sole risk. DrugBank is not intended as a substitute for professional medical advice, diagnosis or treatment..[www.drugbank.ca]","sourceName":"DrugBank","fullInteractionType":[{"comment":"Drug1 (rxcui = 53694, name = nimesulide, tty = IN). Drug2 (rxcui = 5640, name = Ibuprofen, tty = IN). Drug1 is resolved to nimesulide, Drug2 is resolved to Ibuprofen and interaction asserted in DrugBank between Nimesulide and Ibuprofen.","minConcept":[{"rxcui":"53694","name":"nimesulide","tty":"IN"},{"rxcui":"5640","name":"Ibuprofen","tty":"IN"}],"interactionPair":[{"interactionConcept":[{"minConceptItem":{"rxcui":"53694","name":"nimesulide","tty":"IN"},"sourceConceptItem":{"id":"DB04743","name":"Nimesulide","url":"http://www.drugbank.ca/drugs/DB04743#interactions"}},{"minConceptItem":{"rxcui":"5640","name":"Ibuprofen","tty":"IN"},"sourceConceptItem":{"id":"DB01050","name":"Ibuprofen","url":"http://www.drugbank.ca/drugs/DB01050#interactions"}}],"severity":"N/A","description":"The risk or severity of adverse effects can be increased when Ibuprofen is combined with Nimesulide."}]}]}]}
    

    在 iOS 应用中使用 Ti SDK 6.0.1.GA。

    请记住,如果您在 Android 上运行此程序,则 logcat 可能会剪切日志,因为存在字符限制。您可能需要尝试打印console.log(json.fullInteractionTypeGroup) 以确保您可以取回该密钥。

    如果这不起作用,请使用您的 SDK 版本、合金版本、项目目标等更新您的问题。

    【讨论】:

    • 我使用的是 5.2.0,可能有问题吗?是的,我尝试从 json 中记录所有内容。现在我已经解决了使用另一个自定义 Web 服务的问题,它会将完整的响应返回给 Titan 客户端。
    • 那么可能是网络服务的问题。您可以尝试使用 SDK 6.0.1 或在 iOS 上运行您的应用吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多