DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: tino0914
今日帖子: 31
在线用户: 12
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 linlingwei (飞雪) ★☆☆☆☆ -
盒子活跃会员
2021/1/20 19:23:37
标题:
请教个IdHttp.Post问题。谢谢各位 浏览:1569
加入我的收藏
楼主: 函数一:URL静态赋值,正常使用
function PostDemo:string ;
var
  IdHttp : TIdHTTP;
  IdSSLIOHandlerSocketOpenSSL: TIdSSLIOHandlerSocketOpenSSL;
  Url : string;
  jsonToSend : TStringStream; 
begin
IdHttp := TIdHTTP.Create(nil);
  IdSSLIOHandlerSocketOpenSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  IdHttp.IOHandler := IdSSLIOHandlerSocketOpenSSL;
  IdHttp.HandleRedirects := True;
  IdHttp.Request.ContentType := 'application/json';
  try

url:='https://wai.xxxx.com/api/stock?id=3007&code=1548'+
 '&m_data=[{"cine_code":"00323","stock":"14"},{"cine_code":"00711","stock":"25"}]'+
 '×tamp=1611131907&sig=0289503c830be70c601f9666621984f6';
        
    try
      Result :=IdHttp.Post(url,jsonToSend);
    except
      on e : Exception do
      begin
        ShowMessage(e.Message);
      end;
    end;
  finally
   jsonToSend.free;
   IdHttp.free;
  end;

end;

函数二:URL动态赋值,报错,无法使用。这里的url该如何定义?
function PostDemo(url:string):string ; 
var
  IdHttp : TIdHTTP;
  IdSSLIOHandlerSocketOpenSSL: TIdSSLIOHandlerSocketOpenSSL;
  jsonToSend : TStringStream; 
begin
IdHttp := TIdHTTP.Create(nil);
  IdSSLIOHandlerSocketOpenSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  IdHttp.IOHandler := IdSSLIOHandlerSocketOpenSSL;
  IdHttp.HandleRedirects := True;
  IdHttp.Request.ContentType := 'application/json';
  try

    try
      Result :=IdHttp.Post(url,jsonToSend);
    except
      on e : Exception do
      begin
        ShowMessage(e.Message);
      end;
    end;
  finally
   jsonToSend.free;
   IdHttp.free;
  end;

end;

//调用报错
procedure TForm1.Button1Click(Sender: TObject);
var
url:string;
begin
url:='https://wai.xxxx.com/api/stock?id=3007&code=1548'+
 '&m_data=[{"cine_code":"00323","stock":"14"},{"cine_code":"00711","stock":"25"}]'+
 '×tamp=1611131907&sig=0289503c830be70c601f9666621984f6';

Memo1.Text := PostDemo(url);
end;
----------------------------------------------
-
作者:
男 keymark (嬲) ▲▲▲△△ -
普通会员
2021/1/20 20:15:45
1楼: 不知道   
jsonToSend : TStringStream; 
 啥版本的定义  是在Post 里面初始化。。。。
d几?带的版本是几?不会调试吗? ssl dll带了么
----------------------------------------------
[alias]  co = clone --recurse-submodules  up = submodule update --init --recursiveupd = pullinfo = statusrest = reset --hard懒鬼提速https://www.cctry.com/>http://qalculate.github.io/downloads.htmlhttps://www.cctry.com/
作者:
男 linlingwei (飞雪) ★☆☆☆☆ -
盒子活跃会员
2021/1/20 20:41:32
2楼: to keymark:
delphi 10.3.3
dll都带了,用第一种是没问题的,第二种就出错了。
----------------------------------------------
-
作者:
男 keymark (嬲) ▲▲▲△△ -
普通会员
2021/1/20 21:39:08
3楼: 你把 jsonToSend : TStringStream; 
 初始化下吧。按此在新窗口浏览图片
我用的10.4.1
看代码就是没初始化
----------------------------------------------
[alias]  co = clone --recurse-submodules  up = submodule update --init --recursiveupd = pullinfo = statusrest = reset --hard懒鬼提速https://www.cctry.com/>http://qalculate.github.io/downloads.htmlhttps://www.cctry.com/
作者:
男 linlingwei (飞雪) ★☆☆☆☆ -
盒子活跃会员
2021/1/21 9:37:15
4楼: to keymark:
谢谢,按照您说的,问题解决。
----------------------------------------------
-
作者:
男 bahamut8348 (leonna) ★☆☆☆☆ -
普通会员
2021/1/21 11:05:45
5楼: 你这?后面的是提交参数?还有这样发送post请求的?
----------------------------------------------
--
作者:
男 xiaotianwangzi (xiaotian) ★☆☆☆☆ -
普通会员
2021/4/12 23:11:33
6楼: 楼主,你的dll文件能否发一下,我拷贝了你的程序,发现提示“Could not load SSL library”,不知道怎么解决,谢谢。
----------------------------------------------
-
作者:
男 keymark (嬲) ▲▲▲△△ -
普通会员
2021/4/12 23:37:19
7楼: https://wiki.openssl.org/index.php/Binaries
 管网推https://indy.fulgan.com/SSL/
http://whois.chinaz.com/fulgan.com
----------------------------------------------
[alias]  co = clone --recurse-submodules  up = submodule update --init --recursiveupd = pullinfo = statusrest = reset --hard懒鬼提速https://www.cctry.com/>http://qalculate.github.io/downloads.htmlhttps://www.cctry.com/
作者:
男 xiaotianwangzi (xiaotian) ★☆☆☆☆ -
普通会员
2021/4/13 0:04:51
8楼: to keymark,多谢,已经下载。
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行70.3125毫秒 RSS