How do I POST data to a remote URL in Classic ASP?

后端 未结 8 792
走了就别回头了
走了就别回头了 2020-12-08 08:06

I need to POST data to a url in the middle of a script.

  1. User fills out form:
  2. Form submits to process.asp: I need to PO
8条回答
  •  Happy的楠姐
    2020-12-08 08:28

    Use the class described here. This is a pretty good method and I use it all the time:

    http://www.jigar.net/articles/viewhtmlcontent78.aspx

    public class  RemotePost{
         private  System.Collections.Specialized.NameValueCollection Inputs 
         = new  System.Collections.Specialized.NameValueCollection() ;
    
        public string  Url  =  "" ;
        public string  Method  =  "post" ;
        public string  FormName  =  "form1" ;
    
        public void  Add( string  name, string value ){
            Inputs.Add(name, value ) ;
         }
    
         public void  Post(){
            System.Web.HttpContext.Current.Response.Clear() ;
    
             System.Web.HttpContext.Current.Response.Write( "" ) ;
    
             System.Web.HttpContext.Current.Response.Write( string .Format( "" ,FormName)) ;
    
             System.Web.HttpContext.Current.Response.Write( string .Format( "
    " , FormName,Method,Url)) ; for ( int i = 0 ; i< Inputs.Keys.Count ; i++){ System.Web.HttpContext.Current.Response.Write( string .Format( "" ,Inputs.Keys[i],Inputs[Inputs.Keys[i]])) ; } System.Web.HttpContext.Current.Response.Write( "
    " ) ; System.Web.HttpContext.Current.Response.Write( "" ) ; System.Web.HttpContext.Current.Response.End() ; } }

    Use it like:

    RemotePost myremotepost  =  new  RemotePost() ;
    myremotepost.Url  =  "http://www.jigar.net/demo/HttpRequestDemoServer.aspx" ;
    myremotepost.Add( "field1" , "Huckleberry" ) ;
    myremotepost.Add( "field2" , "Finn" ) ;
    myremotepost.Post() ; 
    

提交回复
热议问题