我正在使用异步模块的组合并行地抓取与请求模块的许多链接.
我注意到很多和错误,虽然链接可以访问并使用chrome快速响应.ETIMEDOUTESOCKETTIMEDOUT
我在请求选项中限制maxSockets为2和timeout10000.我使用async.filterLimit()的是2的限制,甚至每次都将并行性降低到2个请求.所以我有2个套接字,2个请求,以及10秒的超时等待来自服务器的标头响应但我得到了这些错误.
这里;我使用的请求配置:
{
...
pool: {
maxSockets: 2
},
timeout: 10000
,
time: true
...
}
Run Code Online (Sandbox Code Playgroud)
这是我用来链接的代码片段:
var self = this;
async.filterLimit(resources, 2, function(resource, callback) {
request({
uri: resource.uri
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
...
} else {
self.emit('error', resource, error);
}
callback(...);
})
}, function(result) {
callback(null, result);
});
Run Code Online (Sandbox Code Playgroud)
我听了错误事件,我看到每当错误代码是ETIMEDOUT连接对象是真/假,所以有时它是连接超时,有时它不是(根据请求文档)
更新:
我决定提升maxSockets至,Infinity …
在阅读有关POST的内容并获取方法时,有一个语句,例如"当使用post方法时它使用HTTP请求Body.它是什么意思"HTTP请求主体".?
使用curl命令行工具,是否可以echo打印或查看请求,而不是发送请求?有点像-n选项吗?我想看到请求标题和正文,以及包含的任何其他内容.除了标题和正文之外还有其他什么吗?
当我使用node.js'request'模块对某个URI进行GET时;
var options = {uri:"aURI", headers:headerData};
request.get(options, function (error, response, body) {
}
Run Code Online (Sandbox Code Playgroud)
错误消息是:
[Error: Exceeded maxRedirects. Probably stuck in a redirect loop.]
Run Code Online (Sandbox Code Playgroud)
并且还有以下消息:
"(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit."
Run Code Online (Sandbox Code Playgroud)
我怎么样setMaxListeners?
我有多个操作(它们是AFNetworking请求),其中包含需要一些时间才能执行的完成块,以及需要在所有请求结束时保存的Core Data对象.
MyCoreDataObject *coreDataObject;
AFHTTPRequestOperation *operation1 = [[AFHTTPRequestOperation alloc] initWithRequest:request1];
[operation1 setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
coreDataObject.attribute1 = responseObject;
sleep(5);
}];
[operation1 start];
AFHTTPRequestOperation *operation2 = [[AFHTTPRequestOperation alloc] initWithRequest:request1];
[operation2 setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
coreDataObject.attribute2 = responseObject;
sleep(10);
}];
[operation1 operation2];
[context save:nil];
Run Code Online (Sandbox Code Playgroud)
当然,这不是我想要的,因为请求是异步的.我尝试添加NSOperationQueue,如下所示:
NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
[operationQueue setMaxConcurrentOperationCount:2];
AFHTTPRequestOperation *operation1 = [[AFHTTPRequestOperation alloc] initWithRequest:request1];
[operation1 setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
coreDataObject.attribute1 = responseObject;
sleep(5);
}];
[operationQueue addOperation:operation1];
AFHTTPRequestOperation *operation2 = [[AFHTTPRequestOperation alloc] initWithRequest:request1];
[operation2 setCompletionBlockWithSuccess:^(AFHTTPRequestOperation …Run Code Online (Sandbox Code Playgroud) 我试图http.request融入Promise:
new Promise(function(resolve, reject) {
var req = http.request({
host: '127.0.0.1',
port: 4000,
method: 'GET',
path: '/api/v1/service'
}, function(res) {
if (res.statusCode < 200 || res.statusCode >= 300) {
// First reject
reject(new Error('statusCode=' + res.statusCode));
return;
}
var body = [];
res.on('data', function(chunk) {
body.push(chunk);
});
res.on('end', function() {
try {
body = JSON.parse(Buffer.concat(body).toString());
} catch(e) {
reject(e);
return;
}
resolve(body);
});
});
req.on('error', function(err) {
// Second reject
reject(err);
});
req.write('test');
}).then(function(data) {
console.log(data); …Run Code Online (Sandbox Code Playgroud) 我是完美主义者类型,我已经使用Google Places API处理网络API调用(仅作为示例),但我觉得它有时很慢或者说我做得不对.有些博客说我应该使用AndroidHttpClient,但我不是,不是吗?
Web API调用我正在使用return json并且我不在UI线程上运行它们,因此使用AsyncTask(AsyncTask是在后台线程上运行的最有效方式,还是我应该使用其他东西?)
请查看我的代码并告诉我它无论如何都会更有效率
public static class NearbySearchRequest extends AsyncTask<String, Void, JSONObject>
{
Exception mException = null;
@Override
protected void onPreExecute()
{
super.onPreExecute();
this.mException = null;
}
@Override
protected JSONObject doInBackground(String... params)
{
StringBuilder urlString = new StringBuilder();
urlString.append("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
urlString.append("key=").append(Constants.GOOGLE_SIMPLE_API_KEY);
urlString.append("&location=").append(params[0]);
urlString.append("&sensor=").append("true");
urlString.append("&language=").append("en-GB");
urlString.append("&name=").append(params[1]);
urlString.append("&rankby=").append("distance");
LogHelper.Log(urlString.toString());
HttpURLConnection urlConnection = null;
URL url = null;
JSONObject object = null;
try
{
url = new URL(urlString.toString());
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.connect();
InputStream inStream = null;
inStream …Run Code Online (Sandbox Code Playgroud) 环顾四周,除了GET和POST请求之外,我无法命名使用任何内容的单个Web应用程序(不是Web服务).这有什么特别的原因吗?某些浏览器(或服务器)不支持任何其他类型的请求吗?或者这仅仅是出于历史原因?我想利用PUT和DELETE请求让我的生活在服务器端变得更容易,但我不愿意,因为没有其他人这样做.
我确信这是一个非常简单的问题,但我对Groovy很新,这是我一直在努力的一段时间.我有一个HttpServletRequest,我需要用它的参数做一些事情.但是,我想要排除1个参数.
以前,我在使用
req.getParameterMap
Run Code Online (Sandbox Code Playgroud)
但是,为了删除一个值,我正在尝试一些类似的东西
def reqParams = req.getParameterMap?.remove('blah');
Run Code Online (Sandbox Code Playgroud)
我知道上面的内容不太合适,但这就是我想要实现的伪代码.我真的需要新的Map和原始的req.getParameterMap()Objects看起来完全一样,除了一个丢失的键.实现这一目标的最佳方法是什么?谢谢!
应用程序记录所有请求的urls.这意味着,使用url参数进行身份验证至关重要,因为这会导致日志中充满对的情况(login=abc&password=123).出于这个原因,我已配置spring-security为从中读取参数request-body.这是通过将以下行添加到request-header:
'Content-Type': 'application/x-www-form-urlencoded'
Run Code Online (Sandbox Code Playgroud)
身体将是:
{'login':'admin', 'password':'password'}
Run Code Online (Sandbox Code Playgroud)
没关系,但QA强迫我通过url参数禁用身份验证的可能性.目前,对以下URL的POST也将进行身份验证:
https://example.com/foo?login=admin&password=password
Run Code Online (Sandbox Code Playgroud)
有没有人知道禁用此选项的技巧?最好带注释.
由于评论,我决定在我的问题中添加更多细节.我的弹簧安全配置spring-security.我有
http.usernameParameter("login")
.passwordParameter("password")
(...)
Run Code Online (Sandbox Code Playgroud)
这使得WebSecurityConfigurerAdapter在参数和正文中搜索登录数据.我希望禁用在网址中搜索这些参数.
httprequest ×10
node.js ×3
asynchronous ×2
http ×2
java ×2
request ×2
android ×1
cocoa-touch ×1
curl ×1
echo ×1
groovy ×1
html ×1
http-headers ×1
ios ×1
map ×1
objective-c ×1
promise ×1
rest ×1
sockets ×1
spring ×1
spring-boot ×1