HTTP 接口返回 JSON 数据
160731
function last(backendTplServer) {
    backendTplServer.app.post('/news/last', function(request, response) {
        var data = Mock.mock(getApiResult({
            'last|10-20': [news]
        }));

        response.json(data);
    });
}
1010381
function json (opts) {
  return {
    ...opts,
    headers: {
      ...opts.headers,
      'content-type': 'application/json'
    },
    body: JSON.stringify(opts.body)
  }
}
298254
def index(cls):
        
        res = requests.get(cls.URL, headers=HEADERS, verify=False)
        res.raise_for_status()
        return res.json()
237965
def get_json_online(self, url):
        
        if not requests:
            return False
        try:
            req = requests.get(url, timeout=.2)
            if not req.ok:
                return []
            return req
        except (requests.exceptions.ConnectTimeout, requests.exceptions.ConnectionError,
                requests.exceptions.ReadTimeout):
            return []
393475
function(){
		// this.bodyが空の場合はEncode.jsの仕様により対象外
		// カンペンには以下のパズルは存在しないのでURL_KANPENPも対象外
		if(!this.body || (this.type!==URL_PZPRV3 && this.type!==URL_PZPRAPP)){ return;}
		
		switch(this.pid){
		case 'ichimaga':
			if     (this.pflag.indexOf('m')>=0){ this.pid = 'ichimagam';}
			else if(this.pflag.indexOf('x')>=0){ this.pid = 'ichimagax';}
			else                               { this.pid = 'ichimaga'; }
			break;
		case 'icelom':
			if(this.pflag.indexOf('a')<0){ this.pid = 'icelom2';}
			break;
		case 'pipelink':
			if(this.body.match(/[0-9]/)){ this.pid = 'pipelinkr';}
			break;
		case 'bonsan':
			if(this.pflag.indexOf('c')<0){
				var col = this.cols, row = this.rows;
				if(this.body.substr(0,((((col-1)*row+4)/5)|0)+(((col*(row-1)+4)/5)|0)||0).match(/[^0]/)){
					this.pid = 'heyabon';
				}
			}
			break;
		case 'kramma':
			if(this.pflag.indexOf('c')<0){
				var len=(this.cols-1)*(this.rows-1), cc=0;
				for(var i=0;i<this.body.length;i++){
					var ca = this.body.charAt(i);
					if(ca.match(/\w/)){
						cc += parseInt(ca,36);
						if(cc<len){ this.pid = 'kramman'; break;}
					}
					else if(ca === '.'){ cc+=36;}
					if(cc>=len){ break;}
				}
			}
			break;
		}
	}
825433
def _http_call(self, url, method, data=None, **kwargs):
        
        response = self._http_response(url, method, data=data, **kwargs)
        if not response.content:
            return {}

        return response.json()
752514
def _http_response(self, url, method, data=None, **kwargs):
        
        header = {'content-type': 'application/json'}

        if data:
            data = json.dumps(data)
        path = url.format(**kwargs)
        logger.debug("%s %s", method.__name__.upper(), path)
        response = method(self.host + path,
                          data=data, headers=header, **self.method_kwargs)
        logger.debug("%s %s", response.status_code, response.reason)
        response.raise_for_status()

        return response
1145079
public static JSONObject getJSONFromUrlViaPOST(String url, List<NameValuePair> params) {

        InputStream is = null;
        JSONObject jObj = null;
        String json = "";

        // Making HTTP request
        try {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            httpPost.setEntity(new UrlEncodedFormEntity(params));

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jObj;

    }
1359726
function json(url, obj, headers, fn){
  if (3 == arguments.length) fn = headers, headers = {};

  var req = new XMLHttpRequest;
  req.onerror = fn;
  req.onreadystatechange = done;
  req.open('POST', url, true);
  for (var k in headers) req.setRequestHeader(k, headers[k]);
  req.send(JSON.stringify(obj));

  function done(){
    if (4 == req.readyState) return fn(null, req);
  }
}
241438
public static function acceptJson()
    {
        $accept = self::getService('HTTP_ACCEPT');
        if (false !== strpos($accept, 'json') || false !== strpos($accept, 'javascript')) {
            return true;
        }
        return false;
    }
713618
HttpConnection asRequest() {
        DatabaseURIHelper builder = getViewURIBuilder();
        for (Map.Entry<String, Object> queryParameter : processParameters(Parameter.Type
                .QUERY_PARAMETER).entrySet()) {
            builder.query(queryParameter.getKey(), queryParameter.getValue());
        }
        Map<String, Object> parameters = processParameters(Parameter.Type.BODY_PARAMETER);
        // if there are no parameters in the body, we do a GET, otherwise we do a POST
        if (parameters == null || parameters.isEmpty()) {
            return Http.GET(builder.build());
        }
        JsonElement body = gson.toJsonTree(parameters);
        HttpConnection conn = Http.POST(builder.build(),  "application/json");
        conn.setRequestBody(body.toString());
        return conn;
    }
1373325
def request(self, url):
        
        self.logger.debug('url:\n' + url)
        try:
            response = urlopen(url)
            return json.loads(response.read().decode('utf-8'))
        except URLError:
            self.logger.info('Server connection problem')
        except Exception:
            self.logger.info('Server format problem')
1291879
def _get_json(self, urlpart):
        
        url = self._url + "/%s" % urlpart
        params = {
            "f" : "json",

        }
        return self._get(url=url,
                            param_dict=params,
                            securityHandler=self._securityHandler,
                            proxy_url=self._proxy_url,
                            proxy_port=self.proxy_port)
449027
function request(opts, callback, agents) {
    var uri = url.parse(opts.url);
    var protocol = uri.protocol || DEFAULT_PROTOCOL;
    protocol = protocol.substring(0, protocol.length - 1);

    var options = {
        hostname: uri.hostname,
        port: uri.port || DEFAULT_PORTS[protocol] || DEFAULT_PORT,
        path: uri.path,
        method: opts.method,
        headers: opts.headers,
        agent: (agents || defaultAgents)[protocol]
    };

    var client = clients[protocol];
    var req = client.request(options, function (res) {
        var data = [];

        res.on('data', function (chunk) {
            data.push(chunk);
        });

        res.on('end', function () {
            if (data.length) {
                data = Buffer.concat(data).toString('utf8');
            }
            else {
                data = '';
            }
            callback(null, res, data);
        });
    });

    req.on('error', callback);

    var abort = req.abort;
    if (opts.timeout) {
        setTimeout(
            function () {
                abort.call(req);
                var e = new Error('TIMEOUT');
                e.code = 'timeout';
                callback(e);
            },
            opts.timeout
        );
    }

    // 重载abort方法 提示错误
    req.abort = function () {
        abort.call(this);
        var e = new Error('ABORT');
        e.code = 'abort';
        callback(e);
    };

    req.write(opts.body || '');
    req.end();

    return req;
}
183864
public RestResponse postJson(final String uri, final String params)
            throws IOException, AppPlatformException {
        return requestJson(getPath(uri), HttpPost.METHOD_NAME, params);
    }
1201359
function view_json(req, src, options, end) {
    load(src
        , {
            authorization: req.headers['authorization'],
            X_Forwarded_For: req.X_Forwarded_For
        }

        , function(status, result) {
            if (status !== true) {
                return end(false, 'status > ' + status);
            };

            result.get(['json'], function(status, data) {
                if (status == true) {
                    if (options.yaml) {
                        data = yaml.safeDump(data, {indent: options.yaml});
                    } else {
                        data = JSON.stringify(data, null, "\t");
                    };

                } else {
                    data = 'status > ' + status;
                };

                end(status, data);
            });
        }
    );
}
981026
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("application/json;charset=UTF-8"); 
        response.setCharacterEncoding("UTF-8"); 
        request.setCharacterEncoding("UTF-8");
        
        String questionStr = request.getParameter("q");
        String n = request.getParameter("n");
        int topN = -1;
        if(n != null && StringUtils.isNumeric(n)){
            topN = Integer.parseInt(n);
        }
        Question question = null;
        List<CandidateAnswer> candidateAnswers = null;
        if (questionStr != null && questionStr.trim().length() > 3) {
            question = SharedQuestionAnsweringSystem.getInstance().answerQuestion(questionStr);
            if (question != null) {
                candidateAnswers = question.getAllCandidateAnswer();
            }
        }
        LOG.info("问题："+questionStr); 
        try (PrintWriter out = response.getWriter()) {
            String json = JsonGenerator.generate(candidateAnswers, topN);
            out.println(json);
            LOG.info("答案："+json);
        }
    }