小编Jam*_*mes的帖子

分段C#文件下载器

一直在尝试用C#编写程序,像大多数下载管理器一样使用多个段下载文件,我遇到了下载的文件已损坏的问题.例如,我下载一个视频,它播放2秒,然后WMP说它无法播放.

我对下载的文件进行了咒骂,看起来整个文件中都有零散的部分,任何人有什么想法?VS报告没有错误.

getPart() 在单独的线程中为每个段调用.

public long start;
public long end;
public int thread;
public Form1 handle;
public myFile handler;
public void getPart()
{
    log("getting part " + start.ToString() + "," + end.ToString());
    HttpWebRequest part = (HttpWebRequest)WebRequest.Create(handler.url);
    part.AddRange((int)start,(int) end);
    HttpWebResponse pr = (HttpWebResponse)part.GetResponse();
    Stream rstream = pr.GetResponseStream();
    log("Beginning part " + start.ToString());
    int totalbytes = 0;
    byte[] buffer = new byte[256];
    int x = rstream.Read(buffer, 0, 256);
    while (x > 0)
    {
        handler.writeFile(buffer, (int)(totalbytes + start), x);
        totalbytes += x;
        x …
Run Code Online (Sandbox Code Playgroud)

c# download httpwebresponse

7
推荐指数
1
解决办法
7321
查看次数

C#获取包数据

我一直在尝试编写一个可以嗅探HTTP头的脚本.到目前为止,我已经将套接字绑定到端口80并且数据包似乎已被接收,但我无法将它们转换为字符串形式.所有输出都是"E"连续.我之前将字节更改为十六进制,似乎有一些数据进入,但当前代码无法将字节更改为字符串.有没有其他方法解码将提供正确字符串的字节?

byte[] input = BitConverter.GetBytes(1);
byte[] buffer = new byte[4096];
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
s.Bind(new IPEndPoint(IPAddress.Parse(strIP), 80));
s.IOControl(IOControlCode.ReceiveAll, input, null);
int bytes;
bytes = s.Receive(buffer);
while (bytes > 0)
{
    log(System.Text.Encoding.ASCII.GetString(buffer, 0, bytes));
    bytes = s.Receive(buffer);
}
Run Code Online (Sandbox Code Playgroud)

c# sockets packets http-headers

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

每个请求会话MVC应用程序的NHibernate问题

我用NHibernate编写了一个C#MVC 3作为ORM,我在大多数页面加载时抛出了一些奇怪的异常.他们似乎主要涉及闭门会议等,我已经检查了大多数常见问题,但没有找到帮助.一些例外包括:

    [[NHibernate.Util.ADOExceptionReporter]] : System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
   at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)

    [[NHibernate.Transaction.AdoTransaction]] : Begin transaction failed
    System.Data.SqlClient.SqlException (0x80131904): The server failed to resume the transaction. Desc:3b00000006.

    [[NHibernate.Transaction.AdoTransaction]] : Commit failed
    System.NullReferenceException: Object reference not set to an instance of an object.

    [[NHibernate.Transaction.AdoTransaction]] : Commit failed
    System.Data.SqlClient.SqlException (0x80131904): The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.

    [[NHibernate.Util.ADOExceptionReporter]] : System.InvalidOperationException: The transaction is either not associated with the current …
Run Code Online (Sandbox Code Playgroud)

c# nhibernate asp.net-mvc session-management session-per-request

3
推荐指数
1
解决办法
5471
查看次数