/*
@param url {string}
@param FormData {Object}
@param Callback {any}
195519
function (url, formData, cb) {

            request.post({url: url, formData: formData}, function (error, response, body) {

                if (error) {
                    return cb(error);
                }

                if (response.statusCode == 200 || response.statusCode == 201) {

                    return cb(null, body);

                } else {

                    return cb(new Error('Server responded with error: ' + response.statusCode));

                }

            })

        }
719121
function (url, data, onDone) {

    SR.Log('url to post: ' + url);

    // construct an HTTP request
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
    
    // set callback when response is returned
    xmlHttp.onloadend = onHttpResponse(xmlHttp, onDone);
	//console.log('data to send:');
	//console.log(data);
	
    // send the collected data as JSON
	// TODO: may be slow in Firefox?
	xmlHttp.send(Object.keys(data).length > 0 ? JSON.stringify(data) : undefined);
}
1120029
function(callback) {
        var headers     = this._formatHeaders(this.headers, this.params);
        if (this.payload != null) {
            headers['content-length'] = new Buffer(this.payload).length;
        } else if (this.method == 'POST' || this.method == 'DELETE' || this.method == 'PUT') {
            headers['content-length'] = 0;
        }
        var client = this.httpClient.http;
        if (this.scheme == 'https') client = this.httpClient.https;
        var httpRequest = client.request({port    : this.port,
                                          host    : this.host,
                                          method  : this.method,
                                          path    : this.uri,
                                          headers : headers},
                                         function(response) {
                                             var data = "";
                                             response.on('data', function(chunk) {
                                                 data += chunk;
                                             });
                                             response.on('end', function() {
                                                 var c = {
                                                     status  : response.statusCode,
                                                     headers : response.headers,
                                                     body    : data
                                                 };
                                                 callback(null, c);
                                             });
                                         });
        httpRequest.on('error', function(e) {
            callback(e, null);
        });
        if (this.payload !== null)
            httpRequest.write(this.payload);
        httpRequest.end();
    }
124897
function(p, callback) {

		var _this = this;
		var error = _this.error;

		// This has to go through a POST request
		if (!_this.isEmpty(p.data) && !('FileList' in window) && _this.hasBinary(p.data)) {

			// Disable XHR and JSONP
			p.xhr = false;
			p.jsonp = false;
		}

		// Check if the browser and service support CORS
		var cors = this.request_cors(function() {
			// If it does then run this...
			return ((p.xhr === undefined) || (p.xhr && (typeof (p.xhr) !== 'function' || p.xhr(p, p.query))));
		});

		if (cors) {

			formatUrl(p, function(url) {

				var x = _this.xhr(p.method, url, p.headers, p.data, callback);
				x.onprogress = p.onprogress || null;

				// Windows Phone does not support xhr.upload, see #74
				// Feature detect
				if (x.upload && p.onuploadprogress) {
					x.upload.onprogress = p.onuploadprogress;
				}

			});

			return;
		}

		// Clone the query object
		// Each request modifies the query object and needs to be tared after each one.
		var _query = p.query;

		p.query = _this.clone(p.query);

		// Assign a new callbackID
		p.callbackID = _this.globalEvent();

		// JSONP
		if (p.jsonp !== false) {

			// Clone the query object
			p.query.callback = p.callbackID;

			// If the JSONP is a function then run it
			if (typeof (p.jsonp) === 'function') {
				p.jsonp(p, p.query);
			}

			// Lets use JSONP if the method is 'get'
			if (p.method === 'get') {

				formatUrl(p, function(url) {
					_this.jsonp(url, callback, p.callbackID, p.timeout);
				});

				return;
			}
			else {
				// It's not compatible reset query
				p.query = _query;
			}

		}

		// Otherwise we're on to the old school, iframe hacks and JSONP
		if (p.form !== false) {

			// Add some additional query parameters to the URL
			// We're pretty stuffed if the endpoint doesn't like these
			p.query.redirect_uri = p.redirect_uri;
			p.query.state = JSON.stringify({callback:p.callbackID});

			var opts;

			if (typeof (p.form) === 'function') {

				// Format the request
				opts = p.form(p, p.query);
			}

			if (p.method === 'post' && opts !== false) {

				formatUrl(p, function(url) {
					_this.post(url, p.data, opts, callback, p.callbackID, p.timeout);
				});

				return;
			}
		}

		// None of the methods were successful throw an error
		callback(error('invalid_request', 'There was no mechanism for handling this request'));

		return;

		// Format URL
		// Constructs the request URL, optionally wraps the URL through a call to a proxy server
		// Returns the formatted URL
		function formatUrl(p, callback) {

			// Are we signing the request?
			var sign;

			// OAuth1
			// Remove the token from the query before signing
			if (p.authResponse && p.authResponse.oauth && parseInt(p.authResponse.oauth.version, 10) === 1) {

				// OAUTH SIGNING PROXY
				sign = p.query.access_token;

				// Remove the access_token
				delete p.query.access_token;

				// Enfore use of Proxy
				p.proxy = true;
			}

			// POST body to querystring
			if (p.data && (p.method === 'get' || p.method === 'delete')) {
				// Attach the p.data to the querystring.
				_this.extend(p.query, p.data);
				p.data = null;
			}

			// Construct the path
			var path = _this.qs(p.url, p.query);

			// Proxy the request through a server
			// Used for signing OAuth1
			// And circumventing services without Access-Control Headers
			if (p.proxy) {
				// Use the proxy as a path
				path = _this.qs(p.oauth_proxy, {
					path: path,
					access_token: sign || '',

					// This will prompt the request to be signed as though it is OAuth1
					then: p.proxy_response_type || (p.method.toLowerCase() === 'get' ? 'redirect' : 'proxy'),
					method: p.method.toLowerCase(),
					suppress_response_codes: true
				});
			}

			callback(path);
		}
	}
1086805
function (requestV1) {
        var modes = {
                urlencoded: 'urlencoded',
                params: 'formdata',
                raw: 'raw',
                binary: 'file'
            },
            data = {},
            rawModeData,
            dataMode = modes[requestV1.dataMode],
            retainEmpty = this.options.retainEmptyValues;

        // set null body if neither data|rawModeData nor dataMode is set, or if the dataMode is explicitly set to null
        // The explicit null check is added to ensure that body is not set in case the dataMode was set to null by the
        // app, but `data` or `rawModeData` was not empty
        if ((!dataMode && _.isEmpty(requestV1.data) && _.isEmpty(requestV1.rawModeData)) ||
            requestV1.dataMode === null) {
            return retainEmpty ? null : undefined;
        }

        // set `rawModeData` if its a string
        if (_.isString(requestV1.rawModeData)) {
            rawModeData = requestV1.rawModeData;
        }
        // check if `rawModeData` is an array like: ['rawModeData']
        else if (Array.isArray(requestV1.rawModeData) &&
            requestV1.rawModeData.length === 1 &&
            _.isString(requestV1.rawModeData[0])) {
            rawModeData = requestV1.rawModeData[0];
        }

        // set data.mode.
        // if dataMode is not set, infer from data or rawModeData
        // at this point either data or rawModeData is set
        if (dataMode) {
            data.mode = dataMode;
        }
        // set `formdata` if rawModeData is not set and data is an array
        // `data` takes higher precedence over `rawModeData`.
        else if (!rawModeData && Array.isArray(requestV1.data || requestV1.rawModeData)) {
            data.mode = 'formdata';
        }
        // set `raw` mode as default
        else {
            data.mode = 'raw';
        }

        if (data.mode === 'raw') {
            if (rawModeData) {
                data[data.mode] = rawModeData;
            }
            else if (_.isString(requestV1.data)) {
                data[data.mode] = requestV1.data;
            }
            else {
                data[data.mode] = ''; // empty string instead of retainEmpty check to have parity with other modes.
            }
        }
        else if (data.mode === 'file') {
            data[data.mode] = { src: rawModeData }; // rawModeData can be string or undefined.
        }
        else {
            // parse data for formdata or urlencoded data modes.
            // `rawModeData` is checked in case its of type `data`.
            data[data.mode] = parseFormData(requestV1.data || requestV1.rawModeData, retainEmpty);
        }

        if (requestV1.dataDisabled) { data.disabled = true; }
        else if (retainEmpty) { data.disabled = false; }

        return data;
    }
394411
function(method, data, callback) {
      xhr.open(method, url, true, user, password);
      if (mimeType != null && !headers.has("accept")) headers.set("accept", mimeType + ",*/*");
      if (xhr.setRequestHeader) headers.each(function(value, name) { xhr.setRequestHeader(name, value); });
      if (mimeType != null && xhr.overrideMimeType) xhr.overrideMimeType(mimeType);
      if (responseType != null) xhr.responseType = responseType;
      if (timeout > 0) xhr.timeout = timeout;
      if (callback == null && typeof data === "function") callback = data, data = null;
      if (callback != null && callback.length === 1) callback = fixCallback(callback);
      if (callback != null) request.on("error", callback).on("load", function(xhr) { callback(null, xhr); });
      event.call("beforesend", request, xhr);
      xhr.send(data == null ? null : data);
      return request;
    }
458152
public function validateFormData(WebRequest $request, Response $response, callable $callback = null)
    {
        $form = $this->searchSubmittedForm($request, $response);
        
        if ($form === null) {
            return Form::NOT_SUBMITTED;
        }
        
        // Validate the data
        $errors = $form->validateFormData($this->framework);
        
        // Execute the custom validation method
        if (is_callable($callback)) {
            $callbackErrors = call_user_func_array($callback, array($this->getFormValues()));
            
            if (is_array($callbackErrors)) {
                $errors = array_merge($errors, $callbackErrors);
            }
        }
        
        if (is_array($errors) && count($errors) > 0) {
            $this->updateErrorBox($form, $errors);
            return Form::DATA_INVALID;
        }
        
        return Form::DATA_VALID;
    }
1102861
function makeFormData( payload ) {
  let body = new FormData()
  for( let k in (payload || {}) ) {
    body.append( k, payload[k] )
  }
  return body
}
1076012
function xhr(url, callback, data) {
        if (!window.XMLHttpRequest || !window.JSON) return;

        var request = new XMLHttpRequest();
        request.onreadystatechange = function() {
            if (callback && request.readyState == 4 && request.status == 200) {
                // server MUST return JSON text
                callback(JSON.parse(request.responseText));
            }
        };
        request.open('POST', url);

        var formData = new FormData();

        // you're passing "message" parameter
        formData.append('message', data);

        request.send(formData);
    }
867648
function(formData) {
    formData = h.getData(formData)
    if (formData && formData.length) {
      formData.forEach(fieldData => prepFieldVars(trimObj(fieldData)))
      d.stage.classList.remove('empty')
    } else if (opts.defaultFields && opts.defaultFields.length) {
      // Load default fields if none are set
      opts.defaultFields.forEach(field => prepFieldVars(field))
      d.stage.classList.remove('empty')
    } else if (!opts.prepend && !opts.append) {
      d.stage.classList.add('empty')
      d.stage.dataset.content = mi18n.get('getStarted')
    }

    if (nonEditableFields()) {
      d.stage.classList.remove('empty')
    }

    h.save()
  }
989270
function API(method, url, data, callback) {
    if (typeof callback === 'undefined') {
        callback  = data;
        data  = {};
    }

    url             = this.prepareUrl(url);
    this.callback   = callback || noop;
    this.data       = data;

    this.options          = extend({}, requestOptions);
    this.options.encoding = this.options.encoding || 'utf-8';

    // these particular set of options should be immutable
    this.options.method         = method;
    this.options.uri            = url;
    this.options.followRedirect = false;

    this[method.toLowerCase()]();

    return this;
}
1299608
def formdata_post(url, fields):
    
    content_type, data = formdata_encode(fields)
    req = urllib2.Request(url, data)
    req.add_header('Content-Type', content_type)
    return urllib2.urlopen(req).read()
1245175
function post($url, $data, $callback = null)
    {
        $ret = new CoURLResult($url, $callback, $this->handle);
        $ret->method = self::METHOD_POST;
        $ret->data = $data;
        $this->requests[$ret->id] = $ret;
        return $ret;
    }
1170725
function(formData, key, value) {
		if (value==undefined) return;
		// HACK: is it a FormData object? then use append
		if (typeof(formData.append)==='function') {
			formData.append(key, value);
		} else {
			formData[key] = value;
		}
	}
1244096
function validateUrl(url) {
        var validate = appOptions.validate,
            type = Object.prototype.toString.call(validate);

        if (type === "[object RegExp]") {
            return validate.test(url);
        } else if (type === "[object Function]") {
            return validate(url);
        } else {
            return true;
        }
    }
524766
function submitForm(page, ph, callback) {
    var oldUrl;
    async.waterfall([
        function (callback) {
            page.get('url', function (url) {
                oldUrl = url;
                callback();
            });
        },
        function (callback) {
            page.evaluate(function () {
                try {
                    document.forms[0].submit();
                    return null;
                } catch (error) {
                    return error;
                }
            }, function (error) {
                // do this because if there is no error, the error is still something so we can't simply do callback(error, page, ph);
                if (error) {
                    callback(error);
                    return;
                }
                callback()
            });
        }, function (callback) {
            checks.pageHasChanged(page, oldUrl, function (error) {
                callback(error);
            });
        }
    ], function (error) {
        callback(error, page, ph);
    });
}
216376
function DataURIScheme_StringToDataURI(str,        // @arg String
                                       mimeType,   // @arg MimeTypeString
                                       callback) { // @arg Function - callback(err:Error|null, String:DataURISchemeString):void
                                                   // @ret void
//{@dev
    $args(DataURIScheme_StringToDataURI, arguments);
//}@dev
    var reader = new FileReader();
    reader.addEventListener("loadend", function() {
        var dataURI = reader.result.replace(";base64,", ";charset=utf-8;base64,");
        // example: data:text/plain;charset=utf-8;base64,YfCgrp9i8J+SqQ==
        //{@dev
        console.info(dataURI);
        //}@dev
        callback(null, dataURI);
    });
    reader.addEventListener("error", function(ev) {
        var err = new Error(ev.target.error.name+": "+ev.target.error.message);
        console.info(err);
        callback(err, "");
    });
    reader.readAsDataURL(new Blob([str], {type: mimeType}));
}