geckofx浏览器内核,设置POST参数时,为什么被截取为100个字符?

oldhunter 2019-04-15 02:31:14
geckofx浏览器内核,设置POST参数时,为什么被截取为100个字符? 需要POST一个json参数串到网页,反复抓包测试,总是被截取为100个字符。
...全文
621 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_45037211 2019-05-09
  • 打赏
  • 举报
回复
人家可能设置了post的大小。 理论上post没有大小,但是人家可以限制大小的。
xiaoxiangqing 2019-04-17
  • 打赏
  • 举报
回复
下载一个抓包工具看一下
oldhunter 2019-04-16
  • 打赏
  • 举报
回复
引用 12 楼 wanghui0380 的回复:
var test =
@"{""limit"":20,""offset"":40,""moduleName"":""queryoffer"",""subDept"":"""",""deptName"":""一二三四五六七"",""underLimit"":""""}";
var charlengh = test.Length; //字符数100,因为我不用gecko,我不知道他的规则,但是你这里的表现是,他似乎并没有根据你设定的utf8规定去写长度
var bufferdata = System.Text.Encoding.UTF8.GetBytes(test);
var bytelengh = bufferdata.Length; //字节数114 ,按照uft8编码算,那里实际上是114字节


谢谢! 这个问题貌似不好解决,先放一下。如果要解决,可能需要看gecko的源代码。


正怒月神 2019-04-15
  • 打赏
  • 举报
回复
你提交给网页? 人家可能设置了post的大小。 理论上post没有大小,但是人家可以限制大小的。
stherix 2019-04-15
  • 打赏
  • 举报
回复
post到网页? 应该是从网页post到服务器吧 可能它只是显示前100字符 服务端确认只收到100个字符了吗
wanghui0380 2019-04-15
  • 打赏
  • 举报
回复
var test = @"{""limit"":20,""offset"":40,""moduleName"":""queryoffer"",""subDept"":"""",""deptName"":""一二三四五六七"",""underLimit"":""""}"; var charlengh = test.Length; //字符数100,因为我不用gecko,我不知道他的规则,但是你这里的表现是,他似乎并没有根据你设定的utf8规定去写长度 var bufferdata = System.Text.Encoding.UTF8.GetBytes(test); var bytelengh = bufferdata.Length; //字节数114 ,按照uft8编码算,那里实际上是114字节
oldhunter 2019-04-15
  • 打赏
  • 举报
回复
引用 9 楼 wanghui0380 的回复:
你试试看用全E文的看看截不截


用英文的参数,没有问题,没有被截取,抓包内容:

POST /article/open/list HTTP/1.1
Host: xxxx
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8, */*
Accept-Language: en-US,en;q=0.5, zh-cn
Accept-Encoding: gzip, deflate, gzip, deflate
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Content-Length: 108

{"limit":20,"offset":20,"moduleName":"queryoffer","subDept":"","deptName":"abcabcabcabcabc","underLimit":""}
oldhunter 2019-04-15
  • 打赏
  • 举报
回复
引用 8 楼 wanghui0380 的回复:
唉,我还真服了。

还没看出来么?上面那个一样,95是字符数,不是字节数。你"deptName":"一二" 这里有中文的,所以他的字节数比字符长,不是人家截了,是你给的不够


引用 5 楼 wanghui0380 的回复:
不用geckofx,只从传统http封包看
1.不建议手动设置Content-Length,因为他容易造成封包解析异常。
2.Content-Length 只的是body区的字节数,而非字符数(故postData.Length.ToString()这里错误)

ps:在科普一下你“普通包”和“json包”,其实他们没有区别,只是普通的包在Content写的是一个表单数据,而post包写的是一个json字符串



我这里的代码,是注释掉的啊,这是之前的旧代码,之前测试用的。

//
// Gecko内核:JSON格式的POST,只能默认写入:Content-Length: 100
//
//postData.SetLength(postData.Length); // 异常:NotImplementedException 未实现该方法或操作
//postData.AddHeader("Content-Length", postData.Length.ToString()); // 异常:对 COM 组件的调用返回了错误 HRESULT E_FAIL



wanghui0380 2019-04-15
  • 打赏
  • 举报
回复
你试试看用全E文的看看截不截
wanghui0380 2019-04-15
  • 打赏
  • 举报
回复
唉,我还真服了。 还没看出来么?上面那个一样,95是字符数,不是字节数。你"deptName":"一二" 这里有中文的,所以他的字节数比字符长,不是人家截了,是你给的不够
oldhunter 2019-04-15
  • 打赏
  • 举报
回复
引用 5 楼 wanghui0380 的回复:
不用geckofx,只从传统http封包看
1.不建议手动设置Content-Length,因为他容易造成封包解析异常。
2.Content-Length 只的是body区的字节数,而非字符数(故postData.Length.ToString()这里错误)

ps:在科普一下你“普通包”和“json包”,其实他们没有区别,只是普通的包在Content写的是一个表单数据,而post包写的是一个json字符串


谢谢!

现在的改了一下POST参数中的字符内容,发现并不是长度的问题,长度减少后,仍会被截取:

POST /article/open/list HTTP/1.1
Host: xxxx
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8, */*
Accept-Language: en-US,en;q=0.5, zh-cn
Accept-Encoding: gzip, deflate, gzip, deflate
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Content-Length: 95

{"limit":20,"offset":20,"moduleName":"queryoffer","subDept":"","deptName":"一二","underLimit":"

而普通的非JSON的POST包,就不会截取,不理解为什么 geckofx 会截取JSON的POST包。


wanghui0380 2019-04-15
  • 打赏
  • 举报
回复
引用 4 楼 oldhunter 的回复:
抓包的内容: POST /article/open/list HTTP/1.1 Host: xxxxx User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8, */* Accept-Language: en-US,en;q=0.5, zh-cn Accept-Encoding: gzip, deflate, gzip, deflate Connection: keep-alive Content-Type: application/json; charset=utf-8 Content-Length: 100 {"limit":20,"offset":20,"moduleName":"queryoffer","subDept":"","deptName":"一二三四五六七","underLim IE内核或HttpWebRequest请求时,抓包的完整POST参数实际是: {"limit":20,"offset":40,"moduleName":"queryoffer","subDept":"","deptName":"一二三四五六七","underLimit":""}
其实你这里就已经出来了,Content-Length: 100是给的字符数,而不是http协议规定的字节数
wanghui0380 2019-04-15
  • 打赏
  • 举报
回复
不用geckofx,只从传统http封包看 1.不建议手动设置Content-Length,因为他容易造成封包解析异常。 2.Content-Length 只的是body区的字节数,而非字符数(故postData.Length.ToString()这里错误) ps:在科普一下你“普通包”和“json包”,其实他们没有区别,只是普通的包在Content写的是一个表单数据,而post包写的是一个json字符串
oldhunter 2019-04-15
  • 打赏
  • 举报
回复
抓包的内容:

POST /article/open/list HTTP/1.1
Host: xxxxx
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8, */*
Accept-Language: en-US,en;q=0.5, zh-cn
Accept-Encoding: gzip, deflate, gzip, deflate
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Content-Length: 100

{"limit":20,"offset":20,"moduleName":"queryoffer","subDept":"","deptName":"一二三四五六七","underLim

IE内核或HttpWebRequest请求时,抓包的完整POST参数实际是:
{"limit":20,"offset":40,"moduleName":"queryoffer","subDept":"","deptName":"一二三四五六七","underLimit":""}

oldhunter 2019-04-15
  • 打赏
  • 举报
回复
引用 2 楼 正怒月神 的回复:
你提交给网页?
人家可能设置了post的大小。
理论上post没有大小,但是人家可以限制大小的。


引用 1 楼 stherix 的回复:
post到网页? 应该是从网页post到服务器吧
可能它只是显示前100字符
服务端确认只收到100个字符了吗


谢谢2位!

我用普通的POST包测试(application/x-www-form-urlencoded),是可以提交的,长度也超过了100个字符。
但JSON的POST包,仍测试失败,有没有可能是POST没有被Gecko内核编码的原因?因为我抓包发现是明文的,与IE内核、普通的HttpWebRequest都不一样,后两者的POST参数都是编码过的。

代码如下:
//
// Gecko内核:以字节流的方式添加POST参数,默认为 null
//
MimeInputStream postData = null;
if (url.HasPostParameters)
{
postData = MimeInputStream.Create();
postData.SetData(url.PostParameters.Trim()); // Gecko内核:POST参数只能写入字符串,不支持写入字节,提示为“只读”

//
// 设置 Content-Type:
// 1、使用POST时,必须手动设置 Content-Type (IE、Gecko内核,都已测试:不会自动添加,必须手动添加)
// 2、选择合适的 ContentType,如:application/x-www-form-urlencoded,或 application/json; charset=utf-8
//
postData.AddHeader("Content-Type", Url.GetProperContentType(url.PostParameters.Trim()));


//
// 已测试:普通的POST包,放在 SetData 方法前后设置都可以,都可以正常写入 Content-Length: 443
//
postData.AddContentLength = true;

//
// Gecko内核:JSON格式的POST,只能默认写入:Content-Length: 100
//
//postData.SetLength(postData.Length); // 异常:NotImplementedException 未实现该方法或操作
//postData.AddHeader("Content-Length", postData.Length.ToString()); // 异常:对 COM 组件的调用返回了错误 HRESULT E_FAIL
}

geckoWebBrowser.Navigate(url.OriginalString, GeckoLoadFlags.IsRefresh, url.Referer, postData, headersData);


110,568

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧