psn_request.js
function URLGET(url, fields, method, callback)
	{
		// method variable is optional
		if (typeof method == "function")
		{
			callback = method;
			method = "GET";
		}

		_URLGET(url, fields, GetHeaders({"Access-Control-Request-Method": method}), method, function(err, body) {
			if (err)
			{
				// got error, bounce it up
				if (callback) callback(err);
				return;
			}
			else
			{
				var JSONBody;
				if (typeof body == "object")
				{
					// already a JSON object?
					JSONBody = body;
				}
				else
				{
					// try to parse JSON body
					if (!body || !/\S/.test(body))
					{
						// string is empty, return empty object
						if (callback) callback(false, {});
						return;
					}
					else
					{
						try
						{
							JSONBody = JSON.parse(body);
						}
						catch(parse_err)
						{
							// error parsing JSON result
							Log("Parse JSON error: " + parse_err + "\r\nURL:\r\n" + url + "\r\nBody:\r\n" + body);
							if (callback) callback("Parse JSON error: " + parse_err);
							return;
						}
					}
				}

				// success! return JSON object
				if (callback) callback(false, JSONBody);
			}
		});
	}
function URLGET(url, fields, method, callback)
	{
		// method variable is optional
		if (typeof method == "function")
		{
			callback = method;
			method = "GET";
		}

		_URLGET(url, fields, GetHeaders({"Access-Control-Request-Method": method}), method, function(err, body) {
			if (err)
			{
				// got error, bounce it up
				if (callback) callback(err);
				return;
			}
			else
			{
				var JSONBody;
				if (typeof body == "object")
				{
					// already a JSON object?
					JSONBody = body;
				}
				else
				{
					// try to parse JSON body
					if (!body || !/\S/.test(body))
					{
						// string is empty, return empty object
						if (callback) callback(false, {});
						return;
					}
					else
					{
						try
						{
							JSONBody = JSON.parse(body);
						}
						catch(parse_err)
						{
							// error parsing JSON result
							Log("Parse JSON error: " + parse_err + "\r\nURL:\r\n" + url + "\r\nBody:\r\n" + body);
							if (callback) callback("Parse JSON error: " + parse_err);
							return;
						}
					}
				}

				// success! return JSON object
				if (callback) callback(false, JSONBody);
			}
		});
	}
function URLGET ( url , fields , method , callback ) { // method variable is optional if ( typeof method == "function" ) { callback = method ; method = "GET" ; } _URLGET ( url , fields , GetHeaders ( { "Access-Control-Request-Method" : method } ) , method , function ( err , body ) { if ( err ) { // got error, bounce it up if ( callback ) callback ( err ) ; return ; } else { var JSONBody ; if ( typeof body == "object" ) { // already a JSON object? JSONBody = body ; } else { // try to parse JSON body if ( ! body || ! / \S / . test ( body ) ) { // string is empty, return empty object if ( callback ) callback ( false , { } ) ; return ; } else { try { JSONBody = JSON . parse ( body ) ; } catch ( parse_err ) { // error parsing JSON result Log ( "Parse JSON error: " + parse_err + "\r\nURL:\r\n" + url + "\r\nBody:\r\n" + body ) ; if ( callback ) callback ( "Parse JSON error: " + parse_err ) ; return ; } } } // success! return JSON object if ( callback ) callback ( false , JSONBody ) ; } } ) ; }
Make a PSN GET request
Make a PSN GET request