小编Fer*_*eia的帖子

是否必须处理HttpClient和HttpClientHandler?

.NET Framework 4.5中的System.Net.Http.HttpClientSystem.Net.Http.HttpClientHandler实现了IDisposable(通过System.Net.Http.HttpMessageInvoker).

using声明文件说:

通常,当您使用IDisposable对象时,您应该在using语句中声明并实例化它.

这个答案使用了这种模式:

var baseAddress = new Uri("http://example.com");
var cookieContainer = new CookieContainer();
using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
using (var client = new HttpClient(handler) { BaseAddress = baseAddress })
{
    var content = new FormUrlEncodedContent(new[]
    {
        new KeyValuePair<string, string>("foo", "bar"),
        new KeyValuePair<string, string>("baz", "bazinga"),
    });
    cookieContainer.Add(baseAddress, new Cookie("CookieName", "cookie_value"));
    var result = client.PostAsync("/test", content).Result;
    result.EnsureSuccessStatusCode();
}
Run Code Online (Sandbox Code Playgroud)

但是微软最明显的例子并没有Dispose()明确地或隐含地调用.例如:

c# idisposable using .net-4.5 dotnet-httpclient

315
推荐指数
7
解决办法
12万
查看次数

如何删除包含租用blob的Azure存储帐户?

我正在使用Windows Azure持久虚拟机.最后,我删除了虚拟机(成功)并尝试删除关联的存储帐户.

删除存储帐户的请求失败.

在删除存储帐户时,在预览门户(manage.windowsazure.com)上出现此错误:

Failed to delete Storage account 'portalvhdscwtwycpsxxxxx'

Details:

Storage account portalvhdscwtwycpsxxxxx has 1 container(s) which have an active image and/or disk artifacts. Ensure those artifacts are removed from the image repository before deleting this storage account.
Run Code Online (Sandbox Code Playgroud)

在以前的门户网站(windows.azure.com)上,我收到此错误:

Submit Failed

Storage account portalvhdscwtwycpsxxxxx has 1 container(s) which have an active image and/or disk artifacts. Ensure those artifacts are removed from the image repository before deleting this storage account.
Run Code Online (Sandbox Code Playgroud)

尝试在Azure存储资源管理器上删除blob本身(30GB VHD)我收到此错误:

There is currently a lease on the blob …
Run Code Online (Sandbox Code Playgroud)

vhd azure azure-storage

153
推荐指数
6
解决办法
5万
查看次数

如何使用JSHint配置Syntastic?

如何使用JSHint的Syntastic Vim插件验证JavaScript代码?

环境:

  • Ubuntu 11.04
  • VIM - Vi IMproved 7.3

我在VIM + JSLint的解决方案之后安装了什么:

  • Vundle
  • 的node.js
  • 节点包管理器
  • jshint,全球
  • 通过Vundle安装的Syntastic(在Vim中使用:BundleInstall命令以确保安装了Syntastic.)

.vimrc中:

set nocompatible               " be iMproved
filetype off                   " required!

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" let Vundle manage Vundle
" required! 
Bundle 'gmarik/vundle'

" My Bundles here:
Bundle 'scrooloose/syntastic'

filetype plugin indent on     " required! 

let g:syntastic_enable_signs=1
let g:syntastic_auto_jump=1
let g:syntastic_stl_format = '[%E{Err: %fe #%e}%B{, }%W{Warn: %fw #%w}]'

set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
Run Code Online (Sandbox Code Playgroud)

寻找已安装的可执行文件:

$ which gjslint …
Run Code Online (Sandbox Code Playgroud)

vim jshint syntastic

44
推荐指数
2
解决办法
3万
查看次数

在服务器上运行单元测试(JAX-RS)

我正在编写一个JAX-RS(Jersey + Maven)应用程序来执行一些棘手的操作(例如调用WAR中嵌入的本机可执行文件).我需要在服务器上运行[部分]单元测试(JUnit4)(运行Tomcat 7.0.22的Amazon Elastic Beanstalk)来检查一切是否正常.

除了RYO(滚动你自己的)之外,还有一种标准的,灵活的方式吗?我发现的东西似乎更多地与开发人员机器上的集成测试(即Jersey测试框架)有关.甚至RYO让我感到困惑......我怎样才能从源包中调用测试包中的代码?

基本上,我想创建一个我可以调用的/ test资源,它将以漂亮的格式从服务器返回我的单元测试结果.如果我可以做/ test/{category}更好

java junit tomcat unit-testing jax-rs

22
推荐指数
1
解决办法
1万
查看次数

如何在ASP.NET MVC 4中默认防止CSRF?

有没有办法确保默认情况下ASP.NET MVC 4表单受CSRF保护?

例如,有没有办法让AntiForgeryToken 自动应用于视图和控制器操作中的所有表单?

关于这个问题的背景:使用ASP.NET MVC的AntiForgeryToken()帮助程序跨站点请求伪造攻击剖析来防止跨站点请求伪造(CSRF).

c# csrf asp.net-mvc-4

22
推荐指数
2
解决办法
1万
查看次数

在Azure表中存储十进制数据类型

Windows Azure的表存储不支持十进制数据类型.

一个建议的解决办法是使用自定义属性序列化小数属性作为字符串:

[EntityDataType(PrimitiveTypeKind.String)]
public decimal Quantity { get; set; }
Run Code Online (Sandbox Code Playgroud)

如何实现此EntityDataType自定义属性,以便可以从Windows Azure表存储和检索十进制属性?

c# azure azure-table-storage

15
推荐指数
2
解决办法
5448
查看次数

验证Web服务器中的路径遍历漏洞

我想验证我的Web应用程序没有路径遍历漏洞.

我正试图用curl它,像这样:

$ curl -v http://www.example.com/directory/../
Run Code Online (Sandbox Code Playgroud)

我希望将HTTP请求显式地发送到/directory/../URL,以测试涉及代理的特定nginx规则不容易受到路径遍历的影响.即,我希望发送此HTTP请求:

> GET /directory/../ HTTP/1.1
Run Code Online (Sandbox Code Playgroud)

但是curl正在重写/URL 的请求,如输出中所示:

* Rebuilt URL to: http://www.example.com/
(...)
> GET / HTTP/1.1
Run Code Online (Sandbox Code Playgroud)

是否可以使用curl此测试,强制它传递请求中的确切URL?如果没有,那么什么是合适的方式?

security curl directory-traversal

14
推荐指数
2
解决办法
4545
查看次数

scrooge-sbt-plugin的存储库是什么?

什么是当前版本的scrooge-sbt-plugin的存储库?或者设置说明是否过时?

根据文档,我将其添加到Play Framework项目中:

在project/plugins.sbt中

addSbtPlugin("com.twitter" %% "scrooge-sbt-plugin" % "3.3.2")
Run Code Online (Sandbox Code Playgroud)

在build.sbt中:

com.twitter.scrooge.ScroogeSBT.newSettings

libraryDependencies ++= Seq(
  "org.apache.thrift" % "libthrift" % "0.8.0",
  "com.twitter" %% "scrooge-core" % "3.3.2",
  "com.twitter" %% "finagle-thrift" % "6.5.0"
)
Run Code Online (Sandbox Code Playgroud)

经过play clean-allplay-compile我得到的输出:

[warn]  module not found: com.twitter#scrooge-sbt-plugin;3.3.2
[warn] ==== typesafe-ivy-releases: tried
[warn]   http://repo.typesafe.com/typesafe/ivy-releases/com.twitter/scrooge-sbt-plugin/scala_2.10/sbt_0.13/3.3.2/ivys/ivy.xml
[warn] ==== sbt-plugin-releases: tried
[warn]   http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.twitter/scrooge-sbt-plugin/scala_2.10/sbt_0.13/3.3.2/ivys/ivy.xml
[warn] ==== local: tried
[warn]   /opt/play-2.2.0/repository/local/com.twitter/scrooge-sbt-plugin/scala_2.10/sbt_0.13/3.3.2/ivys/ivy.xml
[warn] ==== Maven2 Local: tried
[warn]   file:/home/fernando/.m2/repository/com/twitter/scrooge-sbt-plugin_2.10_0.13/3.3.2/scrooge-sbt-plugin-3.3.2.pom
[warn] ==== sonatype-oss-snapshots: tried
[warn]   http://oss.sonatype.org/content/repositories/snapshots/com/twitter/scrooge-sbt-plugin_2.10_0.13/3.3.2/scrooge-sbt-plugin-3.3.2.pom
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/com/twitter/scrooge-sbt-plugin_2.10_0.13/3.3.2/scrooge-sbt-plugin-3.3.2.pom …
Run Code Online (Sandbox Code Playgroud)

scala thrift sbt playframework scrooge

13
推荐指数
1
解决办法
2824
查看次数

等待未知数量的期货

在Scala 2.10中,编写一个返回未来的函数的正确方法是什么,该函数在列表中的所有期货完成时完成?

经过研究和实验,我在Scala工作表中开发了以下代码:

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.concurrent._

object ws2 {

  def executeFutures(futures: Seq[Future[Unit]]): Future[Unit] = {

    def cascadeFutures(futureSeq: Seq[Future[Unit]], f: Future[Unit]): Future[Unit] = {
      futureSeq match {
        case h :: t => h.flatMap { u => cascadeFutures(t, f) }
        case nil => f
      }
    }

    cascadeFutures(futures, Future {})
  }                                               //> executeFutures: (futures: Seq[scala.concurrent.Future[Unit]])scala.concurren
                                                  //| t.Future[Unit]


  Await.ready(executeFutures(Seq(
    Future { println("Future1") },
    Future { println("Future2") },
    Future { println("Future3") }
  )) , 2.seconds)                                 //> Future1
                                                  //| Future2
                                                  //| …
Run Code Online (Sandbox Code Playgroud)

scala future

11
推荐指数
1
解决办法
787
查看次数

ISO 8601格式的当前时间

对于日志记录目的,R脚本如何在UTC时区中以此格式获取ISO 8601字符串的当前日期和时间:

2015-12-31T14:26:56.600374+00:00
Run Code Online (Sandbox Code Playgroud)

as.POSIXlt 似乎是解决方案,文档声称它接受格式参数,但我无法做到这一点(在R版本3.1.3上):

> as.POSIXlt(Sys.time(), "UTC", "%Y-%m-%dT%H:%M:%S")
[1] "2015-04-08 14:37:58 UTC"
> as.POSIXlt(Sys.time(), tz="UTC", format="%Y-%m-%dT%H:%M:%S")
[1] "2015-04-08 14:38:02 UTC"
> as.POSIXct(Sys.time(), tz="UTC", format="%Y-%m-%dT%H:%M:%S")
[1] "2015-04-08 11:38:22 BRT"
Run Code Online (Sandbox Code Playgroud)

r iso8601

9
推荐指数
2
解决办法
6027
查看次数