从http适配器程序读取响应 [英] Reading response from http adapter procedure

查看:154
本文介绍了从http适配器程序读取响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了来自网络服务器的回复:

I have a response from a web server:

  { 
  "errors": [ ],
  "info": [ ], 
  "isSuccessful": true, 
  "responseHeaders": 
  {
  "Connection": "close",
  "Content-Length": "159",
  "Content-Type": "text\/html",
  "Date": "Sat, 20 Feb 2016 11:15:35 GMT", 
  "Server": "Apache",
  "X-Powered-By": "PHP\/5.2.17" }, 
  "responseTime": 705,
  "statusCode": 200, 
  "statusReason": "OK", 
  "text": "True \n<!-- Hosting24 Analytics Code -->\n<script type=\"text\/javascript\" src=\"http:\/\/stats.hosting24.com\/count.php\"><\/script>\n<!-- End Of Analytics Code -->", 
  "totalTime": 706, 
  "warnings": [ ]
  }

要检索真值的我的代码段:

My snippet to retrieve the true value:

 var response = WL.Server.invokeHttp(input);

    // Extract value from the response.
    var type = typeof response; 
    if ("object" == type) {
        if (true == response["isSuccessful"]) {

            // Drill down into the response object.
            var results = response["results"];
            var result = results[0];


            var val = result["text"];

            // Return JSON object
            return val;
        } 
        else {
            // Returning null. Web request was not successful.
            return null;
        }
    } 

如何向下钻取并仅从中提取值text: adapter-impl.js 中的True

How to drill down and extract only the value from the "text": "True" in the adapter-impl.js??

我可以请一些。谢谢。

推荐答案

你能尝试这种方式。还有一件事,看你想要返回 json对象 .so,必须写json格式或转换json。

Can you try this way.one more thing,look you want to return json object.so, must be write json format or convert json.

 var response= WL.Server.invokeHttp(input);

    if (response.statusCode==200 && response.isSuccessful==true){

        var val =response.text

            return {

                data:val

            }


    }
    else{

        return null
    }

这篇关于从http适配器程序读取响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆