我经常听到有人说用HTTP下载.它在技术上意味着什么?
HTTP代表超文本传输协议.因此,从字面上理解它,它意味着文本传输.我使用了一些嗅探工具来监控线路流量.传输的是所有ASCII字符.所以我想我们必须在通过HTTP传输之前将我们想要下载的内容转换为字符.使用HTTP URL编码?或者一些二进制到文本的编码模式,比如base64?但这需要在客户端进行一些解码.
我一直认为TCP可以传输任何数据,所以我猜测HTTP下载是一个误用的词.之所以出现是因为我们通过HTTP查看网页并在该页面上找到一些可下载的链接,然后我们点击它进行下载.实际上,浏览器打开一个TCP连接来下载它.关于HTTP没什么.
任何人都可以轻松一点?
有问题multipart/form-data迫使我手动解析POST请求的参数,因为我已经做了PUT请求.为此我使用了这段代码:
$rawData = file_get_contents('php://input');
Run Code Online (Sandbox Code Playgroud)
但我认为php://input对于POST来说,至少对于php-fpmSAPI来说,它总是空的.
这是调试器的一些图片.POST请求:

PUT使用相同的参数:

有没有办法获得原始POST请求正文?提前致谢.
目前我的HTTP Server具有以下配置:
curl -i http://localhost:3000
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 86400
Access-Control-Allow-Headers: X-Requested-With, Access-Control-Allow-Origin, X-HTTP-Method-Override, Content-Type, Authorization, Accept
Date: Tue, 10 Dec 2013 22:31:40 GMT
Connection: keep-alive
Transfer-Encoding: chunked
Run Code Online (Sandbox Code Playgroud)
尊重Access-Control条目.
这些是否表明发送和接收服务器的内容?
我最好尽量减少这个清单吗?这是否意味着服务器可能更安全,因为访问它的方式较少?
谢谢
嗨,我想写一个节点服务器代码从网址http://freegeoip.net/json/14.12.111.113检索经度和纬度信息,我总是得到这个错误.
Exception: Error: getaddrinfo ENOTFOUND
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
Run Code Online (Sandbox Code Playgroud)
请有人帮忙吗.
这是我正在使用的代码..
var options = {
host: 'http://freegeoip.net/',
path: 'json/14.12.111.113',
method: 'GET'
};
var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
// write data to request body
req.write('data\n');
req.write('data\n');
req.end();
Run Code Online (Sandbox Code Playgroud) 我试图使用java.net.HttpURLConnection在Java中"欺骗"Firefox HTTP POST请求.我使用Wireshark检查发送的HTTP头,因此我(希望)有可靠的信息源,为什么Java结果与理想情况不匹配(使用Firefox).
我已将所有标题字段完全设置为Firefox通过HTTP发送的值,并注意到标题字段的顺序不同.Firefox的输出如下:
POST ...
**Host**
User-Agent
Accept
Accept-Language
Accept-Encoding
Referer
Connection
Content-Type
Content-Length
Run Code Online (Sandbox Code Playgroud)
当我让wireshark在Java中点击我的实现时,它给了我一个稍微不同的字段序列:
POST...
**User-Agent**
Accept
Accept-Language
Accept-Encoding
Referer
Content-Type
Host
Connection
Content-Length
Run Code Online (Sandbox Code Playgroud)
所以基本上,我有所有的领域,只是以不同的顺序.我也注意到,在主机领域与不同的值发送:
www.thewebsite.com(火狐)<---> thewebsite.com(Java的HttpURLConnection类),虽然我传递的字符串,以httpUrlConnection.setRequestProperty与"WWW".
我还没有分析Wireshark的字节输出,但我知道服务器Location在我的响应的头字段中没有返回相同的内容.
我的问题是:
(1)是否可以控制请求中的头字段的顺序,如果是,是否可以使用HttpURLConnection?如果没有,是否可以使用Java直接控制HTTP头中的字节?[我不拥有服务器,所以我唯一的希望让POST方法正常工作是通过我的应用程序假装是Firefox,服务器并不是真的很冗长,我唯一的信息是:Apache with PHP]
(2)有没有办法修复上面描述的setRequestProperty()问题("www")?
(3)还有什么可以重要的?(我需要关注底层,TCP ......?)
谢谢你的评论.
PS.我试图模拟一个没有发送cookie的情况,这样我就可以忽略这个效果了.
说我有以下HTTP请求:
GET /4 HTTP/1.1
Host: graph.facebook.com
Run Code Online (Sandbox Code Playgroud)
并且服务器返回以下响应:
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Cache-Control: private, no-cache, no-store, must-revalidate
Content-Type: text/javascript; charset=UTF-8
ETag: "539feb8aee5c3d20a2ebacd02db380b27243b255"
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Pragma: no-cache
X-FB-Rev: 1070755
X-FB-Debug: pC4b0ONpdhLwBn6jcabovcZf44bkfKSEguNsVKuSI1I=
Date: Wed, 08 Jan 2014 01:22:36 GMT
Connection: keep-alive
Content-Length: 172
{"id":"4","name":"Mark Zuckerberg","first_name":"Mark","last_name":"Zuckerberg","link":"http:\/\/www.facebook.com\/zuck","username":"zuck","gender":"male","locale":"en_US"}
Run Code Online (Sandbox Code Playgroud)
由于Content-Lengh标题取决于内容的长度,我不能简单地用Content-Length: 172字符串分割 .如何单独提取JSON和标头?它们对我的计划都很重要.我正在使用此代码来获取响应:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("graph.facebook.com", 80))
s.send("GET /"+str(id)+"/picture HTTP/1.1\r\nHost: graph.facebook.com\r\n\r\n")
data = s.recv(1024)
s.close()
json_string = (somehow extract this)
userdata = json.loads(json_string)
Run Code Online (Sandbox Code Playgroud) 我一直在使用我正在开发的脚本的问题,因为我没有收到任何输出,并且脚本的内存使用量随着时间的推移而变得越来越大.我已经发现问题在于我正在使用Requests库检查的一些URL.我期待下载一个网页,但我下载了一个大文件.然后将所有这些数据存储在内存中导致我的问题.
我想知道的是; 有什么办法让请求库检查下载的是什么?用wget我可以看到:长度:710330974(677M)[application/zip].
这些信息是否在带有请求的标题中可用?如果是这样,有一种方法可以在确定它不是HTML网页时终止下载?
提前致谢.
我有一个触发HTTP请求的服务.此请求使用$ rootScope.config对象(存储了我的基本URL),但出于某种原因,当我使用$ httpBackend时,$ rootScope未正确加载.
服务:
myAppServices.factory('Auth', function($rootScope, $http, $cookieStore){
return {
logout: function(success, error) {
$http.get($rootScope.config.apiUrl + '/users/logout').then(function(response){
}, function(response) {
});
}
Run Code Online (Sandbox Code Playgroud)
测试:
describe('services', function() {
var Auth;
var $httpBackend;
var $cookieStore;
var $rootScope;
beforeEach(function() {
module('myApp.services');
});
beforeEach(inject(function($injector) {
$httpBackend = $injector.get('$httpBackend');
$cookieStore = $injector.get('$cookieStore');
$rootScope = $injector.get('$rootScope');
Helper = $injector.get('Helper');
Auth = $injector.get('Auth');
}));
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
describe('logout', function() {
it('should make a request and invoke callback', function() {
// I try to set $rootScope …Run Code Online (Sandbox Code Playgroud) 我必须通过GET方法发出HTTP请求来发送短信.该链接包含GET变量形式的信息,例如
http://www.somelink.com/file.php?from=12345&to=67890&message=hello%20there
Run Code Online (Sandbox Code Playgroud)
运行脚本之后,必须仿佛有人点击了链接并激活了短信发送过程.
我找到了一些关于获取请求和卷曲的链接,什么不是,这一切都让人困惑!
在rails中我发了一个api的帖子并得到了回复,但我不知道如何获取信息并找到"code"变量的值.
$ response
#<Net::HTTPOK 200 OK readbody=true>
$ puts response.body
{"success":true,"button":{"code":"dfhdsg7f23hjgfs7be7","type":"buy_now","style":"none","text":"Send to MeBrah","name":"MeBrah","description":"Coins you're willing to give me.","custom":"6","callback_url":null,"success_url":null,"cancel_url":null,"info_url":null,"auto_redirect":false,"price":{"cents":40000000,"currency_iso":"BTC"},"variable_price":true,"choose_price":false,"include_address":false,"include_email":false}}
$ response.code
"200"
Run Code Online (Sandbox Code Playgroud)
我知道代码变量也是相同的"dfhdsg7f23hjgfs7be7"我只是好奇什么命令会返回它的值.
http ×10
node.js ×2
post ×2
python ×2
angularjs ×1
download ×1
http-headers ×1
httpbackend ×1
httprequest ×1
java ×1
json ×1
php ×1
regex ×1
request ×1
ruby ×1
security ×1
sms ×1
tcp ×1
unit-testing ×1
web ×1