服务器违反了协议怎么办,服务器违反了协议。 Section = ResponseStatusLine in c#

我花了一整天的时间来解决这个问题。我有一个自定义的网络服务器,并请求从Chrome或POSTman ReST客户端工作正常。一旦我在c#中使用webclient或httpwebrequest,我就会得到:服务器违反协议。 Section = ResponseStatusLine尝试将zip文件传输到客户端时。服务器违反了协议。 Section = ResponseStatusLine in c#

我曾尝试:

public static bool SetAllowUnsafeHeaderParsing20()

{

//Get the assembly that contains the internal class

Assembly aNetAssembly = Assembly.GetAssembly(typeof(System.Net.Configuration.SettingsSection));

if (aNetAssembly != null)

{

//Use the assembly in order to get the internal type for the internal class

Type aSettingsType = aNetAssembly.GetType("System.Net.Configuration.SettingsSectionInternal");

if (aSettingsType != null)

{

//Use the internal static property to get an instance of the internal settings class.

//If the static instance isn't created allready the property will create it for us.

object anInstance = aSettingsType.InvokeMember("Section", BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.NonPublic, null, null, new object[] { });

if (anInstance != null)

{

//Locate the private bool field that tells the framework is unsafe header parsing should be allowed or not

FieldInfo aUseUnsafeHeaderParsing = aSettingsType.GetField("useUnsafeHeaderParsing", BindingFlags.NonPublic | BindingFlags.Instance);

if (aUseUnsafeHeaderParsing != null)

{

aUseUnsafeHeaderParsing.SetValue(anInstance, true);

return true;

}

}

}

}

return false;

}

中的app.config

我也试图保持存活=虚假和混乱与头太/

这是WebRequest的,其失败的client2Downloadfile电话:

private void sendManifest()

{

Uri remoteuri = new Uri(Properties.Settings.Default.masterurl);

SetAllowUnsafeHeaderParsing20();

using (WebClient client = new WebClient())

{

NameValueCollection reqparm = new NameValueCollection();

reqparm.Add("application", "TestApp");

reqparm.Add("manifest", manifest);

try

{

byte[] responsebytes = client.UploadValues(Properties.Settings.Default.masterurl, "POST", reqparm);

string responsebody = Encoding.UTF8.GetString(responsebytes);

if (responsebody != "")

{

using (WebClient client2 = new WebClient())

{

client2.DownloadFile(Properties.Settings.Default.masterurl + "//" + responsebody + "transfer.zip", "c:\\temp.zip");

}

}

}

catch (Exception e)

{

Console.WriteLine(e.ToString());

}

}

}

的Web服务器响应可以看出:

http://gplus2.net:9532/97e456f0-9b57-4315-b03d-40a67f76d440/transfer.zip

任何援助是非常感谢,因为我已经字面上用完了想法。这显然是一个格式错误的服务器标题,但我保持在最低限度。

2014-05-19

spanout

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值