|
|
导航: |
论坛 -> Web应用开发
斑竹:bodies |
|
作者: |
|
2023/9/4 9:46:54 |
标题: |
TNetHTTPRequest 自定义头post向服务器请求数据失败 |
浏览:703 |
|
加入我的收藏 |
楼主: |
用CustomHeaders时报错 nthtprqst1.CustomHeaders['Accept']:='application/json, text/plain, */*' ; nthtprqst1.CustomHeaders['Accept-Encoding']:='gzip, deflate'; nthtprqst1.CustomHeaders['Accept-Language']:='zh-CN,zh;q=0.9'; nthtprqst1.CustomHeaders['Content-Type']:='application/x-www-form-urlencoded; charset=UTF-8'; nthtprqst1.CustomHeaders['User-Agent']:='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'; nthtprqst1.CustomHeaders['Cookie'] :='XSRF-TOKEN='+edt1.Text+'; SESSION='+edt2.Text; nthtprqst1.CustomHeaders['X-XSRF-TOKEN'] :=edt1.Text; nthtprqst1.Post(url,data,jsontoget); 如果定义一个heads:TNetHeaders变量把自定义头信息加入这个变量,可以得到数据。 nthtprqst1.post(url,data,jsontoget,nil,heads) ;
----------------------------------------------
- |
作者: |
|
2023/9/4 9:49:54 |
1楼: |
求大佬解答
----------------------------------------------
-
|
作者: |
|
2023/9/4 14:14:42 |
2楼: |
nthtprqst1.CustomHeaders['Accept']:='application/json, text/plain, */*' ; nthtprqst1.CustomHeaders['Accept-Encoding']:='gzip, deflate'; nthtprqst1.CustomHeaders['Accept-Language']:='zh-CN,zh;q=0.9'; nthtprqst1.CustomHeaders['Content-Type']:='application/x-www-form-urlencoded; charset=UTF-8'; nthtprqst1.CustomHeaders['User-Agent']
这几个它有固定自己属性的。
----------------------------------------------
相信自己,若自己都不相信,那还有谁可信。
|
作者: |
|
2023/9/4 14:31:27 |
3楼: |
举例: GET / HTTP/1.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9 Cache-Control: no-cache Connection: keep-alive ASPSESSIon_IDSADCTBDR=LFLLOOPBPAAMOLAFNFECOFEA; 2ccc%5F=login=letianwuji Host: bbs.2ccc.com Pragma: no-cache Sec-GPC: 1 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
IdHttp := THTTPClient.Create; IdHttp.AllowCookies := true; IdHttp.HandleRedirects := true; IdHTTP.Accept := 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8'; IdHTTP.AcceptEncoding:= 'gzip, deflate'; IdHTTP.AcceptLanguage:= 'zh-CN,zh;q=0.9'; IdHttp.CustomHeaders['Cache-Control'] := 'no-cache'; IdHttp.CustomHeaders['Connection'] := 'keep-alive'; IdHttp.CustomHeaders['Cookie'] := IdHttp.CustomHeaders['Host'] := 'bbs.2ccc.com'; IdHttp.CustomHeaders['Pragma'] := 'no-cache'; IdHttp.CustomHeaders['Sec-GPC'] := '1'; IdHttp.CustomHeaders['Upgrade-Insecure-Requests'] := '1'; IdHTTP.UserAgent := 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36';
此帖子包含附件:
 大小:32.6K |
----------------------------------------------
相信自己,若自己都不相信,那还有谁可信。
|
作者: |
|
2023/9/4 14:40:36 |
4楼: |
谢谢letianwuji分享
----------------------------------------------
http://www.cnblogs.com/tulater/
|
作者: |
|
2023/9/5 9:42:49 |
5楼: |
@letianwuji (大器晚成) 是不是这几个属性,不能加入到CustomHeaders里面?
此帖子包含附件:
 大小:32.6K |
----------------------------------------------
-
|
作者: |
|
2023/9/5 11:00:04 |
6楼: |
@letianwuji (大器晚成) 用你的方法试了,还是不行,调试的时候,没有自定义的头信息。。。。。。
----------------------------------------------
-
|
作者: |
|
2023/9/5 18:01:11 |
7楼: |
用AddHeader 试试. /// <summary>Add a Header to the current request.</summary> /// <param name="AName">Name of the Header.</param> /// <param name="AValue">Value associted.</param> procedure AddHeader(const AName, AValue: string); virtual; abstract;
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
|
作者: |
|
2023/9/6 9:55:08 |
8楼: |
不可能,我自己都用来post 模拟登陆服务器的。 可用。
----------------------------------------------
相信自己,若自己都不相信,那还有谁可信。
|
作者: |
|
2023/9/6 14:50:20 |
9楼: |
用TNetHTTPClient Get试试。
----------------------------------------------
123
|
|