delphi 之 get post

來源:互聯網
上載者:User

標籤:

http://www.cnblogs.com/ccqin/archive/2012/08/22/2650348.htmldelphi 之 get post

沒測試過這個

var      Source:   TMemoryStream;      Response:   TStringStream   ;  begin  try          //   Set   the   properties   for   HTTP          idHTTP.Request.Username   :=   ‘www ‘;          idHTTP.Request.Password   :=   ‘www ‘;  //         idHTTP1.Request.ProxyServer   :=   ‘11.133.190.13 ‘;  //         idHTTP1.Request.ProxyPort   :=   StrToIntDef( ‘80 ‘,   80);          idHTTP.Request.ContentType   :=   ‘application/x-www-form-urlencoded ‘;            Response   :=   TStringStream.Create( ‘ ‘);              try                      Source   :=   TMemoryStream.Create;                      try                          Source.LoadFromFile( ‘unsub.xml ‘);   //發送這個XML包,反向取消請求                          idHTTP.Post( ‘http://222.333.444.555/dsmp/dsmp.wsdl ‘,   Source,   Response);                      finally                        //   Source.Free;                      end;                  memo.Lines.Text   :=   Response.DataString;//返回的字串,可以把它存為XML就可以                  memo.Lines.SaveToFile( ‘unsubresp.xml ‘);         //返回的反向取消應答包              finally                  Response.Free;              end;      finally      end

這個方法試了 可以用

以下僅供參考,要求在web頁面寫特殊的字元,根據返回的結果判斷是否登陸成功,使用者名稱,密碼方式見下:

procedure   TForm1.Button1Click(Sender:   TObject);  var      Url:   string;      Response   :   TStringStream;      Request   :   TStrings;  begin      Memo1.Clear;      Response   :=   TStringStream.Create( ‘ ‘);      try          Request   :=   TStringList.Create;          try              Request.Append( ‘txtUserId=hengli&txtPassword=ysj);              url   :=   ‘http://192.168.1.33/nmmis/index.aspx ‘;              IdHTTP1.Request.ContentType   :=   ‘application/x-www-form-urlencoded ‘;              IdHTTP1.Post(Url,   Request,   Response);              Memo1.Lines.Text   :=   Response.DataString;          finally              FreeAndNil(Request);          end;      finally          FreeAndNil(Response);      end;  end;

通過idhttp上傳檔案到web上,然後返回上傳的檔案路徑。

function   UpLoagFile(FileName:   String):   string;  var      obj   :   TIdMultiPartFormDataStream;      Url:   String;  begin      obj   :=   TIdMultiPartFormDataStream.Create;      try          obj.AddFile( ‘Image ‘,FileName,   GetMIMETypeFromFile(FileName));          http.Request.ContentType   :=   obj.RequestContentType;          obj.Position   :=   0;          Url   :=     ‘http://192.168.1.44/insertImage.aspx ‘;          Result   :=   http.Post(Url,   obj);      finally          obj.Free;      end;  end;  服務端,C#:  private   void   Page_Load(object   sender,   System.EventArgs   e)  {          foreach(string   f   in   Request.Files.AllKeys)          {                    string   fileName,   fullName;                  HttpPostedFile   postFile   =   Request.Files[f];                    if   (postFile.ContentLength   >   10)                  {          fileName   =   postFile.FileName;        //GetFileName(   fileName,   out   fullName   );        fullName   =   "UpLoad/aaa.jpg "        postFile.SaveAs   (   Server.MapPath   (   fullName   )   );        Response.Write   (fullName);  }          }  }

delphi 之 get post

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.