小编Edg*_*gar的帖子

为什么模数运算符在javascript中返回小数?

为什么49.90 % 0.10在JavaScript中返回0.09999999999999581?我预计它会是0.

javascript floating-point modulus

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

从C#NUnit一个接一个地在多个浏览器中运行Selenium测试

我正在寻找推荐/最好的方法让Selenium测试一个接一个地在几个浏览器中执行.我正在测试的网站并不大,所以我还不需要并行解决方案.

我有一个通常的测试设置方法[SetUp],[TearDown][Test].当然,SetUp可以ISelenium使用我想要测试的任何浏览器来实例化一个新对象.

所以我想要的是以编程方式说:这个测试将按顺序在Chrome,IE和Firefox上运行.我怎么做?

编辑:

这可能会有所帮助.我们正在使用CruiseControl.NET在成功构建之后启动NUnit测试.有没有办法将参数传递给NUnit可执行文件,然后在测试中使用该参数?这样我们就可以使用不同的浏览器参数多次运行NUnit.

c# selenium nunit

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

如何更改默认的ASP.NET MVC Web API媒体格式化程序?

我有一个Web API项目,它返回一些产品数据.它根据请求的Accept标头(JSON/XML)正确协商返回类型.问题是,如果没有指定Accept头,它返回JSON,但我希望它默认返回XML.如何更改Global.asax中的内容协商默认值?

c# xml asp.net-mvc asp.net-web-api

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

如何在C#中使用Tor控制协议?

我正在尝试以编程方式将命令发送到Tor控制端口以使其刷新链.我无法在C#中找到任何示例,我的解决方案无法正常工作.请求超时.我运行了服务,我可以看到它在控制端口上监听.

public string Refresh()
{
    TcpClient client = new TcpClient("localhost", 9051);
    string response = string.Empty;
    string authenticate = MakeTcpRequest("AUTHENTICATE\r\n", client);
    if (authenticate.Equals("250"))
    {
        response = MakeTcpRequest("SIGNAL NEWNYM\r\n", client);
    }
    client.Close();
    return response;
}

public string MakeTcpRequest(string message, TcpClient client)
{
    client.ReceiveTimeout = 20000;
    client.SendTimeout = 20000;
    string proxyResponse = string.Empty;

    try
    {
        // Send message
        StreamWriter streamWriter = new StreamWriter(client.GetStream());
        streamWriter.Write(message);
        streamWriter.Flush();

        // Read response
        StreamReader streamReader = new StreamReader(client.GetStream());
        proxyResponse = streamReader.ReadToEnd();
    }
    catch (Exception ex)
    {
        // Ignore …
Run Code Online (Sandbox Code Playgroud)

.net c# network-programming tcpclient tor

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

MVC 3不绑定可空长

我创建了一个测试网站来调试我遇到的问题,看起来我要么传递JSON数据错误,要么MVC只能绑定可空的longs.当然,我正在使用最新的MVC 3版本.

public class GetDataModel
{
    public string TestString { get; set; }
    public long? TestLong { get; set; }
    public int? TestInt { get; set; }
}

[HttpPost]
public ActionResult GetData(GetDataModel model)
{
    // Do stuff
}
Run Code Online (Sandbox Code Playgroud)

我发布了一个具有正确JSON内容类型的JSON字符串:

{ "TestString":"test", "TestLong":12345, "TestInt":123 }
Run Code Online (Sandbox Code Playgroud)

长期没有约束,它总是空的.如果我把这个值放在引号中,它就可以工作,但我不应该这样做,不是吗?我需要为该值设置自定义模型绑定器吗?

c# nullable model-binding asp.net-mvc-3

12
推荐指数
1
解决办法
3666
查看次数

GZipStream没有读取整个文件

我有一些代码可以下载gzip压缩文件并对其进行解压缩.问题是,我无法解压缩整个文件,它只读取前4096个字节,然后再读取大约500个字节.

Byte[] buffer = new Byte[4096];
int count = 0;
FileStream fileInput = new FileStream("input.gzip", FileMode.Open, FileAccess.Read, FileShare.Read);
FileStream fileOutput = new FileStream("output.dat", FileMode.Create, FileAccess.Write, FileShare.None);
GZipStream gzipStream = new GZipStream(fileInput, CompressionMode.Decompress, true);

// Read from gzip steam
while ((count = gzipStream.Read(buffer, 0, buffer.Length)) > 0)
{
    // Write to output file
    fileOutput.Write(buffer, 0, count);
}

// Close the streams
...
Run Code Online (Sandbox Code Playgroud)

我检查了下载的文件; 它在压缩时为13MB,包含一个XML文件.我手动解压缩了XML文件,内容就在那里.但是,当我使用此代码执行此操作时,它只输出XML文件的最开头.

任何人都有任何想法为什么会发生这种情况?

c# gzipstream

8
推荐指数
1
解决办法
2618
查看次数

如何将原始HTTP响应解析为HttpListenerResponse?

如果我将原始HTTP响应作为字符串:

HTTP/1.1 200 OK
日期:2010年5月11日星期二07:28:30 GMT
到期:-1
Cache-Control:private,max-age = 0
Content-Type:text/html; charset = UTF-8
服务器:gws
X-XSS-Protection:1; mode = block
连接:关闭

<!doctype html><html>...</html>
Run Code Online (Sandbox Code Playgroud)

有没有一种简单的方法可以将它解析为一个HttpListenerResponse对象?或者至少是某种.NET对象,所以我不必使用原始响应.

我目前正在做的是提取标题键/值对并在HttpListenerResponse上设置它们.但是有些头文件无法设置,然后我必须剪切响应的主体并将其写入OutputStream.但是身体可以被gzipped,或者它可能是一个图像,我还无法工作.并且一些响应在任何地方都包含随机字符,这看起来像编码问题.这很麻烦.

我正在获得原始响应,因为我正在使用SOCKS发送HTTP请求.我正在处理的程序基本上是一个HTTP代理,它可以通过SOCKS代理路由请求,就像Privoxy那样.

c# proxy httpresponse httplistener socks

6
推荐指数
1
解决办法
7240
查看次数

使用来自 Firefox 扩展的属性触发自定义事件

我有一个 Firefox 扩展,可以修改用户正在查看的页面内容。作为该过程的一部分,扩展程序需要触发扩展程序本身添加到页面源的自定义事件。我无法将参数传递给该自定义事件。我究竟做错了什么?

插入head页面的脚本块:

document.addEventListener("show-my-overlay", EX_ShowOverlay, false, false, true);

function EX_ShowOverlay(e) {
    alert('Parameter: ' + e.index);
    // ...
}
Run Code Online (Sandbox Code Playgroud)

扩展中的代码:

var event = content.document.createEvent("Events");
event.initEvent("show-my-overlay", true, true);
event['index'] = 123;
content.document.dispatchEvent(event);
Run Code Online (Sandbox Code Playgroud)

事件被成功触发,但e.index未定义。

我设法通过在页面上创建一个元素然后让事件处理程序找到该元素并读取其属性来使其工作,但它并不优雅。我想在没有元素的情况下做到这一点。

编辑:

我也尝试用 触发事件CustomEvent,但它在处理程序中引发异常:

var event = new CustomEvent('show-my-overlay', { detail: { index: 123 } });
content.document.dispatchEvent(event);

function EX_ShowOverlay(e) {
    alert('Parameter: ' + e.detail.index);
    // ...
}
Run Code Online (Sandbox Code Playgroud)

访问属性“详细信息”的权限被拒绝

javascript firefox firefox-addon dom-events

6
推荐指数
2
解决办法
1346
查看次数

从CruiseControl.NET执行命令行命令

我在CruiseControl.NET配置中有这个代码块:

<exec>
    <executable>C:\Windows\System32\cmd.exe</executable>
    <buildArgs>/C SETX SELENIUM_BROWSER googlechrome /M</buildArgs>
</exec>
Run Code Online (Sandbox Code Playgroud)

接下来是一个NUnit执行命令,它将在我的网站上运行一些Selenium测试.我们的想法是,在运行测试之前,此命令会更改测试浏览器(系统环境变量).

问题是该命令似乎不起作用.测试仍在使用默认浏览器Firefox.如果我手动更改环境变量,它可以工作.

我究竟做错了什么?

编辑:

我尝试将命令放在批处理文件中并执行它,但它仍然无效:

<exec executable="C:\CCNet\setChrome.bat" />
Run Code Online (Sandbox Code Playgroud)

批处理文件内容:

SETX SELENIUM_BROWSER googlechrome /M
Run Code Online (Sandbox Code Playgroud)

cruisecontrol.net selenium nunit

5
推荐指数
1
解决办法
3681
查看次数

通过代理进行基本授权请求Web服务,NTLM授权不起作用

我有一个需要基本授权的Web服务和一个需要NTLM授权的Internet代理后面的用户.我还有一个表单应用程序,它调用Web服务并询问用户Web服务凭据(与NTLM凭据不同).

我得到了应用程序配置(WCF ServiceModel),它使用默认代理凭据,请求正在使用代理进行身份验证,但在使用Web服务进行身份验证后,由于某种原因它不会发送请求正文.

如果我在没有NTLM代理的情况下在本地测试,则该过程有效.对很长的例子感到抱歉,但我不得不包括它们.

第一次要求:

发送:

POST http://www.myservice.com/service.asmx HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/MyMethod"
Host: www.myservice.com
Content-Length: 329
Expect: 100-continue
Accept-Encoding: gzip, deflate
Proxy-Connection: Keep-Alive

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body>[...]</s:Body></s:Envelope>
Run Code Online (Sandbox Code Playgroud)

接收:

HTTP/1.1 407 Proxy Authentication Required
Proxy-Authenticate: NTLM
Proxy-Authenticate: BASIC realm="corporaterealm"
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Proxy-Connection: close
Set-Cookie: BCSI-CS-36204A5A7BBD24D9=2; Path=/
Connection: close
Content-Length: 1057
Proxy-Support: Session-Based-Authentication

[...]
Run Code Online (Sandbox Code Playgroud)

第二次请求:

发送:

POST http://www.myservice.com/service.asmx HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/MyMethod"
Accept-Encoding: gzip, deflate,gzip, deflate
Proxy-Authorization: NTLM TlRMTVNTUAABAAAAB7IIoggACAAxAAAACQAJACgAAAAFASgKAAAAD1dTUkswNDg3MENPTUVUTkVU
Host: www.myservice.com
Content-Length: 0
Run Code Online (Sandbox Code Playgroud)

接收:

HTTP/1.1 …
Run Code Online (Sandbox Code Playgroud)

wcf proxy ntlm web-services basic-authentication

5
推荐指数
1
解决办法
7664
查看次数