Tag: get

使用PHP创建RESTful API和网站

我有一个我之前写的PHP应用程序,我想添加一个RESTful API。 我还想扩展网站,使其更像是一个Rails应用程序,就您调用的URL来获取系统中的项目。 有没有办法用Railsy方式调用PHP中的项目而不创建各种文件夹和索引页面? 如何在不使用GET查询标记的情况下在PHP中调用信息?

Node.js – 在HTTP GET请求查询中发送时,数组转换为对象

以下Node.js代码: var request = require(‘request’); var getLibs = function() { var options = { packages: [‘example1’, ‘example2’, ‘example3’], os: ‘linux’, pack_type: ‘npm’ } request({url:’http://localhost:3000/package’, qs:options}, function (error , response, body) { if (! error && response.statusCode == 200) { console.log(body); } else if (error) { console.log(error); } else{ console.log(response.statusCode); } }); }(); 发送以下接收的http GET请求查询: {“packages”=>{“0″=>”example1”, […]

在Heroku环境中将POST请求视为GET

我有奇怪的情况。 我有一个RoR应用程序,它提供了我从Java应用程序连接的REST API。 我正在本地开发RoR,并在Heroku环境中部署它。 无论如何(我尝试从Java APP,Mozilla REST客户端等)我尝试发送应该由api控制器中的create action处理的POST HTTP请求。 在localhost上 – 一切都按预期工作。 在Heroku生产环境中 – POST请求被视为正常的GET。 以下是此资源的路线: api_v1_items GET /api/v1/items(.:format) api/v1/items#index {:format=>:json} POST /api/v1/items(.:format) api/v1/items#create {:format=>:json} api_v1_item GET /api/v1/items/:id(.:format) api/v1/items#show {:format=>:json} PATCH /api/v1/items/:id(.:format) api/v1/items#update {:format=>:json} PUT /api/v1/items/:id(.:format) api/v1/items#update {:format=>:json} DELETE /api/v1/items/:id(.:format) api/v1/items#destroy {:format=>:json} 所以我正在尝试对/api/v1/items传递所有必要参数的POST请求。 在localhost中,响应是正确的: Started POST “/api/v1/items?token=l4XOHrhDApPqTp1u4TxBjQ” for 127.0.0.1 at 2014-05-15 22:11:49 +0200 Processing by […]

如何使用User-Agent获取URL并通过Ruby中的某个代理超时?

如果我需要通过某个代理获取URL,如何获取URL,它必须具有max n的超时 。 秒和用户代理 ? require ‘nokogiri’ require ‘net/http’ require ‘rexml/document’ def get_with_max_wait(param, proxy, timeout) url = “http://example.com/?p=#{param}” uri = URI.parse(url) proxy_uri = URI.parse(proxy) http = Net::HTTP.new(uri.host, 80, proxy_uri.host, proxy_uri.port) http.open_timeout = timeout http.read_timeout = timeout response = http.get(url) doc = Nokogiri.parse(response.body) doc.css(“.css .goes .here”)[0].content.strip end 上面的代码通过超时的代理获取URL,但它缺少User-Agent 。 如何使用 User-Agent获取它?