首页 > > > POST分包提交失败,怎么修改成不分包呢,
using System;
using System.Text;
using System.Net;
using System.IO;
namespace HelloWorldApplication
{
class HelloWorld
{
static void Main(string[] args)
{
/* 我的第一个 C# 程序/
string ew = PostWebRequest("http://154.206.44.193:8080", "{"id":10005,"arg":{"gameid":0}}");
/ 我的第一个 C# 程序*/
Console.WriteLine("我的第一个 C# 程序");
Console.WriteLine(ew);
Console.ReadKey();
}
public static string PostWebRequest(string postUrl, string paramData)
{
string ret = string.Empty;
try
{
Encoding dataEncode = System.Text.Encoding.GetEncoding("utf-8");
byte[] byteArray = dataEncode.GetBytes(paramData); //转化
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
webReq.Method = "POST";
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.ContentLength = byteArray.Length;
webReq.Timeout = 30000;
webReq.SendChunked = false;
webReq.KeepAlive = false;
Stream newStream = webReq.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);//写入参数
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.Default);
ret = sr.ReadToEnd();
sr.Close();
response.Close();
newStream.Close();
}
catch (Exception ex)
{
return "响应超时";
}
return ret;
}
}
}
//这个地址是C++接口调用地址,分包提交会失败,成功率不能达到100%,测试过期时间调长,也是一样
//在线工具http://www.dooccn.com/csharp/ 测试可以
//SendChunked = false;
//类型:System.Boolean如果发送了分块请求,则为 true;否则为 false。默认值为 false。
//以上测试没效果来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2370/viewspace-3170483/ ,如需转载,请注明出处,否则将追究法律责任。