/// Create a web form object from strings.
///
/// This function mimics how we get the data from command line, but might need some
/// pre-processing.
///
/// * url - Of the format http://example.pcom:80
/// * data - Parameters of the format key=value&key2=value2
/// * request - Specify request, has the format GET/POST
/// * encoding - Specify request, has the format URL/JSON
/// * headers - A vector of raw headers of the format: Type: value
Create a web form object from strings.
This function mimics how we get the data from command line, but might need some
pre-processing.


Create a web form object from strings . This function mimics how we get the data from command line but might need some pre - processing .
pub fn new_from_strings(url: &str, data: &str, request: &str, encoding: &str, headers: Vec<String>) -> Form   {
        let (protocol, address, port, path) = Form::split_url(url);
        let req = match request {
            "GET"  => enums::RequestMethod::GET,
            "POST" => enums::RequestMethod::POST,
            _      => enums::RequestMethod::GET,
        };
        let enc = match encoding    {
            "URL"  => enums::ParameterEncoding::URL,
            "JSON" => enums::ParameterEncoding::JSON,
            _      => enums::ParameterEncoding::URL,
        };
        let mut head = Vec::new();
        for h in headers.iter() {
            head.push( header::WebHeader::create_string(h) );
        }
        let params = Form::create_parameters(data);
        Form    {
            ip_addr: address,
            port: port,
            uri: path,
            params: params,
            request: req,
            encoding: enc,
            headers: head,
            protocol: protocol,
        }
    }
pub fn new_from_strings ( url : & str , data : & str , request : & str , encoding : & str , headers : Vec < String > ) -> Form { let ( protocol , address , port , path ) = Form :: split_url ( url ) ; let req = match request { " " => enums :: RequestMethod :: GET , " " => enums :: RequestMethod :: POST , _ => enums :: RequestMethod :: GET , } ; let enc = match encoding { " " => enums :: ParameterEncoding :: URL , " " => enums :: ParameterEncoding :: JSON , _ => enums :: ParameterEncoding :: URL , } ; let mut head = Vec :: new ( ) ; for h in headers . iter ( ) { head . push ( header :: WebHeader :: create_string ( h ) ) ; } let params = Form :: create_parameters ( data ) ; Form { ip_addr : address , port : port , uri : path , params : params , request : req , encoding : enc , headers : head , protocol : protocol , } }
Create a web form object from strings.
Create a web form object from strings .
url
&str
data
&str
request
&str
encoding
&str
headers
Vec<String>