zoukankan      html  css  js  c++  java
  • Idhttp实现HTTP Post提交

    问题的由来:

    我有两个asp文件
    a.asp内容:
    <html>
      <head>
      </head>
        <body>
          <form action="b.asp" method=post target="_self">
            <P><INPUT id="Text1" type="text" name="Text1">
            <INPUT id="Submit1" type="submit" value="Submit" name="Submit1"></P>
          </form>
        </body>
    </html>

    b.asp内容:
    <html>
    <body>
       <%response.Write request.Form.Count%>
       <%response.Write request.Form("text1")%>
    </body>
    </html>
    在IE中点a.asp的提交按钮时显示2,但用Delphi 6 该如何实现呢?我用TNMHTTP的post, NMHTTP1.Post('http://localhost/test/b.asp', 'text1=ddssssddd'); 显示了Count,但text1的内容无法显示,听说TNMHTTP存在编码的问题,我又用Delphi6的Indy Http,就是Delphi自带的例子,Delphi安装目录下的Demo\Indy\HTTPClient也无法显示,不知是何原因?
     

    回复的代码


    {sHttp 是idhttp控件
       netinfo是我自自定义的记录类型,用来保存用户设置的代理的信息。

    }
    application.ProcessMessages;
     with sHttp do
     begin
      Disconnect;
      //Request.UserAgent:='Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)';
      Request.UserAgent:='CSDN Helper ver1.0 Build0402';
      RedirectMaximum:=0;
      Request.ContentType:='application/x-www-form-urlencoded';   //这句最重要了
      Request.ContentLength:=length(memo1.Text);                  //这个也要。
     if (netinfo.flg_UseProxy=true) then
      begin
       Request.ProxyUsername:=netInfo.prx_User;
       Request.ProxyPassword:=netInfo.prx_Pass;
       Request.ProxyServer:=netInfo.prx_IP;
       Request.ProxyPort:=StrToIntDef(netInfo.prx_Port,80);
     end;
      Rsp:=TStringStream.Create('');
      try
        Post(csdn.ReplyUrl,memo1.Lines,Rsp);
        reStr:= Rsp.DataString;
      finally
        Rsp.Free;
      end;
     end;  //end of With
     

  • 相关阅读:
    HDU 3572 Task Schedule(拆点+最大流dinic)
    POJ 1236 Network of Schools(Tarjan缩点)
    HDU 3605 Escape(状压+最大流)
    HDU 1166 敌兵布阵(分块)
    Leetcode 223 Rectangle Area
    Leetcode 219 Contains Duplicate II STL
    Leetcode 36 Valid Sudoku
    Leetcode 88 Merge Sorted Array STL
    Leetcode 160 Intersection of Two Linked Lists 单向链表
    Leetcode 111 Minimum Depth of Binary Tree 二叉树
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668574.html
Copyright © 2011-2022 走看看