diff --git a/src/PortableRest.Tests/PortableRest.Tests.csproj b/src/PortableRest.Tests/PortableRest.Tests.csproj
index cbc3b24..23d4ab3 100644
--- a/src/PortableRest.Tests/PortableRest.Tests.csproj
+++ b/src/PortableRest.Tests/PortableRest.Tests.csproj
@@ -126,6 +126,8 @@
+
+
diff --git a/src/PortableRest.Tests/packages.config b/src/PortableRest.Tests/packages.config
index 1104448..4efbee6 100644
--- a/src/PortableRest.Tests/packages.config
+++ b/src/PortableRest.Tests/packages.config
@@ -1,8 +1,9 @@
-
-
-
-
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/PortableRest.sln b/src/PortableRest.sln
index f2793e5..f66991c 100644
--- a/src/PortableRest.sln
+++ b/src/PortableRest.sln
@@ -19,6 +19,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
PortableRest.nuspec = PortableRest.nuspec
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PortableRestJs", "PortableRestJs\PortableRestJs.csproj", "{3D45C414-46FA-4427-8B6C-26C7DEDF40DC}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -29,6 +31,14 @@ Global
{A3546D1A-CE87-49BB-800A-98018C1FCA00}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3546D1A-CE87-49BB-800A-98018C1FCA00}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3546D1A-CE87-49BB-800A-98018C1FCA00}.Release|Any CPU.Build.0 = Release|Any CPU
+ {500BCEAB-8F93-4BDE-84DB-D21147323837}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {500BCEAB-8F93-4BDE-84DB-D21147323837}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {500BCEAB-8F93-4BDE-84DB-D21147323837}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {500BCEAB-8F93-4BDE-84DB-D21147323837}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3D45C414-46FA-4427-8B6C-26C7DEDF40DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3D45C414-46FA-4427-8B6C-26C7DEDF40DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3D45C414-46FA-4427-8B6C-26C7DEDF40DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3D45C414-46FA-4427-8B6C-26C7DEDF40DC}.Release|Any CPU.Build.0 = Release|Any CPU
{EE7DCA96-146F-496B-9C8E-5368487DEE82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE7DCA96-146F-496B-9C8E-5368487DEE82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE7DCA96-146F-496B-9C8E-5368487DEE82}.Release|Any CPU.ActiveCfg = Release|Any CPU
diff --git a/src/PortableRest/PortableRest.csproj b/src/PortableRest/PortableRest.csproj
index 80f7bc9..d1495b5 100644
--- a/src/PortableRest/PortableRest.csproj
+++ b/src/PortableRest/PortableRest.csproj
@@ -83,6 +83,34 @@
+ ..\packages\Microsoft.Bcl.Async.1.0.14-rc\lib\portable-net40+sl4+win8+wp71\Microsoft.Threading.Tasks.dll
+
+
+ ..\packages\Microsoft.Bcl.Async.1.0.14-rc\lib\portable-net40+sl4+win8+wp71\Microsoft.Threading.Tasks.Extensions.dll
+
+
+ ..\packages\Newtonsoft.Json.4.5.11\lib\portable-net40+sl4+wp7+win8\Newtonsoft.Json.dll
+
+
+ ..\packages\Microsoft.Net.Http.2.1.3-beta\lib\portable-net40+sl4+win8+wp71\System.Net.Http.dll
+
+
+ ..\packages\HttpClient.Compression.1.0.0-beta3\lib\portable-net4+sl4+wp7+win8\System.Net.Http.Compression.dll
+
+
+ ..\packages\Microsoft.Net.Http.2.1.3-beta\lib\portable-net40+sl4+win8+wp71\System.Net.Http.Extensions.dll
+
+
+ ..\packages\Microsoft.Net.Http.2.1.3-beta\lib\portable-net40+sl4+win8+wp71\System.Net.Http.Primitives.dll
+
+
+ ..\packages\Microsoft.Bcl.1.0.16-rc\lib\portable-net40+sl4+win8+wp71\System.Runtime.dll
+
+
+ ..\packages\Microsoft.Bcl.1.0.16-rc\lib\portable-net40+sl4+win8+wp71\System.Threading.Tasks.dll
+
+
+ ..\packages\Zlib.Portable.1.9.2\lib\portable-net4+sl4+wp71+win8\Zlib.Portable.dll
..\packages\Microsoft.Bcl.Async.1.0.165\lib\portable-net40+sl4+win8+wp71\Microsoft.Threading.Tasks.dll
@@ -112,6 +140,7 @@
+
diff --git a/src/PortableRestJs/PortableRestJs.csproj b/src/PortableRestJs/PortableRestJs.csproj
new file mode 100644
index 0000000..c0104db
--- /dev/null
+++ b/src/PortableRestJs/PortableRestJs.csproj
@@ -0,0 +1,130 @@
+
+
+
+
+ Debug
+ AnyCPU
+
+
+ 2.0
+ {3D45C414-46FA-4427-8B6C-26C7DEDF40DC}
+ {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
+ Library
+ Properties
+ PortableRestJs
+ PortableRestJs
+ v4.0
+ true
+
+
+
+
+ ..\
+ true
+
+
+ true
+ full
+ false
+ bin\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\
+ TRACE
+ prompt
+ 4
+
+
+
+
+ ..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ test.aspx
+ ASPXCodeBehind
+
+
+ test.aspx
+
+
+ xmlTest.aspx
+ ASPXCodeBehind
+
+
+ xmlTest.aspx
+
+
+
+
+
+ Web.config
+
+
+ Web.config
+
+
+
+ 10.0
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
+
+
+
+
+
+
+
+
+ True
+ True
+ 0
+ /
+ http://localhost:56617/
+ False
+ False
+
+
+ False
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/PortableRestJs/Properties/AssemblyInfo.cs b/src/PortableRestJs/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..bf8cf93
--- /dev/null
+++ b/src/PortableRestJs/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("PortableRestJs")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("PortableRestJs")]
+[assembly: AssemblyCopyright("Copyright © 2013")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("f94e82b7-743c-4e6f-bf1d-fd1c7ea7a860")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/src/PortableRestJs/Web.Debug.config b/src/PortableRestJs/Web.Debug.config
new file mode 100644
index 0000000..2e302f9
--- /dev/null
+++ b/src/PortableRestJs/Web.Debug.config
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/PortableRestJs/Web.Release.config b/src/PortableRestJs/Web.Release.config
new file mode 100644
index 0000000..c358444
--- /dev/null
+++ b/src/PortableRestJs/Web.Release.config
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/PortableRestJs/Web.config b/src/PortableRestJs/Web.config
new file mode 100644
index 0000000..c72873f
--- /dev/null
+++ b/src/PortableRestJs/Web.config
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/PortableRestJs/portableRest.js b/src/PortableRestJs/portableRest.js
new file mode 100644
index 0000000..08dd162
--- /dev/null
+++ b/src/PortableRestJs/portableRest.js
@@ -0,0 +1,446 @@
+(function (window)
+{
+ "use strict";
+
+ if (window.PortableRest !== undefined)
+ {
+ return;
+ }
+
+ window.PortableRest = {};
+
+ window.PortableRest.ContentTypes =
+ {
+ FormUrlEncoded: "application/x-www-form-urlencoded",
+ Json: "application/json",
+ Xml: "application/xml",
+ MultipartFormData: "multipart/form-data",
+ };
+
+ window.PortableRest.HttpMethod =
+ {
+ Delete: "DELETE",
+ Get: "GET",
+ Head: "HEAD",
+ Options: "OPTIONS",
+ Post: "POST",
+ Put: "PUT",
+ Trace: "TRACE"
+ };
+
+ window.PortableRest.HttpStatusCode =
+ {
+ Continue: 100,
+ SwitchingProtocols: 101,
+ Processing: 102,
+
+ OK: 200,
+ Created: 201,
+ Accepted: 202,
+ NonAuthoritativeInformation: 203,
+ NoContent: 204,
+ ResetContent: 205,
+ PartialContent: 206,
+ MultiStatus: 207,
+ AlreadyReported: 208,
+ ImUsed: 226,
+ LowOnStorageSpace: 250,
+
+ MultipleChoices: 300,
+ MovedPermanently: 301,
+ Found: 302,
+ SeeOther: 303,
+ NotModified: 304,
+ UseProxy: 305,
+ SwitchProxy: 306,
+ TemporaryRedirect: 307,
+ PermanentRedirect: 308,
+
+ BadRequest: 400,
+ Unauthorized: 401,
+ PaymentRequired: 402,
+ Forbidden: 403,
+ NotFound: 404,
+ MethodNotAllowed: 405,
+ NotAcceptable: 406,
+ ProxyAuthenticationRequired: 407,
+ RequestTimeout: 408,
+ Conflict: 409,
+ Gone: 410,
+ LengthRequired: 411,
+ PreconditionFailed: 412,
+ RequestEntityTooLarge: 413,
+ RequestURITooLong: 414,
+ UnsupportedMediaType: 415,
+ RequestedRangeNotSatisfiable: 416,
+ ExpectationFailed: 417,
+ ImATeapot: 418,
+ UnprocessableEntity: 422,
+ Locked: 423,
+ FailedDependency: 424,
+ UpgradeRequired: 426,
+ PreconditionRequired: 428,
+ TooManyRequests: 429,
+ RequestHeaderFieldsTooLarge: 431,
+
+ InternalServerError: 500,
+ NotImplemented: 501,
+ BadGateway: 502,
+ ServiceUnavailable: 503,
+ GatewayTimeout: 504,
+ HTTPVersionNotSupported: 505,
+ VariantAlsoNegotiates: 506,
+ InsufficientStorage: 507,
+ LoopDetected: 508,
+ NotExtended: 510,
+ NetworkAuthenticationRequired: 511
+ };
+
+ window.PortableRest.ParameterEncoding =
+ {
+ Base64: 0,
+ ByteArray: 1,
+ UriEncoded: 2,
+ Unencoded: 3
+ };
+
+ window.PortableRest.RestRequest = function (resource, method)
+ {
+ /// Creates a new RestRequest instance for a given Resource and Method.
+ /// The specific resource to access.
+ /// The HTTP method to use for the request.
+ ///
+ ///
+ ///
+ ///
+
+ if (!(this instanceof window.PortableRest.RestRequest))
+ {
+ return new window.PortableRest.RestRequest(resource, method);
+ }
+
+ this._urlSegments = [];
+ this._parameters = [];
+ this._credentials = null;
+
+ this.contentType = window.PortableRest.ContentTypes.FormUrlEncoded;
+ this.method = method || window.PortableRest.HttpMethod.Get;
+ this.resource = resource || "";
+ };
+
+ window.PortableRest.RestRequest.prototype.addUrlSegment = function (key, value)
+ {
+ /// Replaces tokenized segments of the URL with a desired value.
+ ///
+ ///
+
+ this._urlSegments.push({ key: key, value: value });
+ };
+
+ window.PortableRest.RestRequest.prototype.addParameter = function (key, value, encoding)
+ {
+ /// Adds an unnamed parameter to the body of the request.
+ ///
+ ///
+ ///
+
+ encoding = encoding || window.PortableRest.ParameterEncoding.UriEncoded;
+
+ this._parameters.push({ key: key, value: value, encoding: encoding });
+ };
+
+ window.PortableRest.RestRequest.prototype.addQueryString = function (key, value)
+ {
+ /// Appends a key/value pair to the end of the existing QueryString in a URI.
+ ///
+ ///
+
+ if (typeof value !== "string")
+ {
+ value = value.toString();
+ }
+
+ this._urlSegments.push({ key: key, value: value, isQueryString: true });
+ };
+
+ window.PortableRest.RestRequest.prototype.setCredentials = function (user, password)
+ {
+ ///
+ ///
+ ///
+
+ this._credentials = { user: user, password: password };
+ };
+
+ window.PortableRest.RestRequest.prototype.clearCredentials = function ()
+ {
+ this._credentials = null;
+ };
+
+ window.PortableRest.RestRequest.prototype._getFormattedResource = function (baseUrl)
+ {
+ ///
+ ///
+ ///
+
+ var hasQueryString = false;
+ for (var urlSegmentsIndex = 0, urlSegmentsLength = this._urlSegments.length; urlSegmentsIndex < urlSegmentsLength; urlSegmentsIndex++)
+ {
+ var segment = this._urlSegments[urlSegmentsIndex];
+ if (segment.isQueryString)
+ {
+ hasQueryString = true;
+ continue;
+ }
+ this.resource = this.resource.replace("{" + segment.key + "}", encodeURIComponent(segment.value));
+ }
+
+ if (hasQueryString)
+ {
+ var queryString = "";
+ for (var urlSegmentsIndex = 0, urlSegmentsLength = this._urlSegments.length; urlSegmentsIndex < urlSegmentsLength; urlSegmentsIndex++)
+ {
+ var segment = this._urlSegments[urlSegmentsIndex];
+ if (!segment.isQueryString)
+ {
+ continue;
+ }
+ if (queryString)
+ {
+ queryString += "&";
+ }
+ queryString += segment.key + "=" + segment.value;
+ }
+ this.resource = this.resource + (this.resource.indexOf("?") !== -1 ? "&" + queryString : "?" + queryString);
+ }
+
+ if ((baseUrl !== null) && (baseUrl !== undefined))
+ {
+ if ((this.resource !== null) && (this.resource !== undefined) && (this.resource !== "") && (this.resource.indexOf("/") === 0))
+ {
+ this.resource = this.resource.substr(1);
+ }
+
+ this.resource = ((this.resource === null) || (this.resource === undefined) || (this.resource === "")) ? baseUrl : baseUrl + "/" + this.resource;
+ }
+
+ return this.resource;
+ };
+
+ window.PortableRest.RestRequest.prototype._getRequestBody = function ()
+ {
+ ///
+ ///
+
+ var parameters = "";
+
+ switch (this.contentType)
+ {
+ case window.PortableRest.ContentTypes.Xml:
+ throw new Error("Sending XML is not yet supported, but will be added in a future release.");
+ case window.PortableRest.ContentTypes.Json:
+ parameters = this._parameters.length > 0 ? JSON.stringify(this._parameters[0].value) : "";
+ break;
+ case window.PortableRest.ContentTypes.FormUrlEncoded:
+ case window.PortableRest.ContentTypes.MultipartFormData:
+ if (this.contentType === window.PortableRest.ContentTypes.MultipartFormData)
+ {
+ if (typeof FormData === "undefined")
+ {
+ throw new Error("Multipart-FormData is only supported in newer browsers");
+ }
+
+ parameters = new FormData();
+ }
+
+ for (var parameterIndex = 0, parametersLength = this._parameters.length; parameterIndex < parametersLength; parameterIndex++)
+ {
+ var parameter = this._parameters[parameterIndex];
+ if (this.contentType === window.PortableRest.ContentTypes.MultipartFormData)
+ {
+ parameters.append(parameter.key, parameter.value);
+ }
+ else
+ {
+ parameters = parameters + (parameters.length > 0 ? "&" : "") + encodeURIComponent(parameter.key) + "=" + encodeURIComponent(parameter.value.toString());
+ }
+ }
+ break;
+ }
+
+ return parameters;
+ };
+
+ window.PortableRest.RestClient = function ()
+ {
+ /// Creates a new instance of the RestClient class.
+ ///
+ ///
+
+ if (!(this instanceof window.PortableRest.RestClient))
+ {
+ return new window.PortableRest.RestClient();
+ }
+
+ this.baseUrl = "";
+ this._headers = [];
+ this._defaultCredentials = null;
+ this._callbackListeners = [];
+ };
+
+ window.PortableRest.RestClient.prototype.addCallbackListener = function (fn)
+ {
+ /// Note: Adding same function more than once does nothing.
+ ///
+
+ if (this._callbackListeners.indexOf(fn) !== -1)
+ {
+ return;
+ }
+
+ this._callbackListeners.push(fn);
+ };
+
+ window.PortableRest.RestClient.prototype.removeCallbackListener = function (fn)
+ {
+ ///
+ ///
+
+ var itemIndex = this._callbackListeners.indexOf(fn);
+ if (itemIndex !== -1)
+ {
+ this._callbackListeners.splice(itemIndex, 1);
+ }
+ };
+
+ window.PortableRest.RestClient.prototype._fireCallbackListeners = function (requestCallback, response, status, error)
+ {
+ ///
+ ///
+ ///
+ ///
+ ///
+
+ if ((requestCallback !== undefined) && (requestCallback !== null) && (typeof requestCallback === "function"))
+ {
+ requestCallback(response, status, error);
+ }
+
+ for (var callbackIndex = 0, callbacksLength = this._callbackListeners.length; callbackIndex < callbacksLength; callbackIndex++)
+ {
+ var callback = this._callbackListeners[callbackIndex];
+ callback(response, status, error);
+ }
+ };
+
+ window.PortableRest.RestClient.prototype.setDefaultCredentials = function (user, password)
+ {
+ ///
+ ///
+ ///
+
+ this._defaultCredentials = { user: user, password: password };
+ };
+
+ window.PortableRest.RestClient.prototype.clearDefaultCredentials = function ()
+ {
+ this._defaultCredentials = null;
+ };
+
+ window.PortableRest.RestClient.prototype.addHeader = function (key, value)
+ {
+ /// Adds a header for a given string key and string value.
+ /// The header to add.
+ /// The value of the header being added.
+
+ this._headers.push({ key: key, value: value });
+ };
+
+ window.PortableRest.RestClient.prototype.execute = function (restRequest, callback)
+ {
+ /// Executes an asynchronous request to the given resource and deserializes the response
+ /// The RestRequest to execute.
+ ///
+ ///
+ /// The callback function is passed either two or three parameters.
+ /// 1. The response. If the content type was XML or JSON and can be parsed then parsed version is here, otherwise just the response as received.
+ /// 2. The HTTP Status code. This is the code received from the server and can be compared to PortableRest.HttpStatusCode.
+ /// 3. In case the JSON parsing fails this is the error thrown the the parser. Otherwise not passed.
+ ///
+
+ var url = restRequest._getFormattedResource(this.baseUrl);
+
+ var client = new XMLHttpRequest();
+
+ for (var headerIndex = 0, headersLength = this._headers.length; headerIndex < headersLength; headerIndex++)
+ {
+ var header = this._headers[headerIndex];
+ client.setRequestHeader(header.key, header.value);
+ }
+
+ restRequest._credentials = restRequest._credentials || this._defaultCredentials;
+
+ if (restRequest._credentials === null)
+ {
+ client.open(restRequest.method, url, true);
+ }
+ else
+ {
+ client.open(restRequest.method, url, true, restRequest._credentials.user, restRequest._credentials.password);
+ }
+
+ var body = null;
+
+ if ((restRequest.method !== window.PortableRest.HttpMethod.Get) && (restRequest.method !== window.PortableRest.HttpMethod.Head) && (restRequest.method !== window.PortableRest.HttpMethod.Trace))
+ {
+ if (restRequest.contentType !== window.PortableRest.ContentTypes.MultipartFormData)
+ {
+ client.setRequestHeader("Content-Type", restRequest.contentType);
+ }
+ body = restRequest._getRequestBody();
+ }
+
+ var $this = this;
+ if (((callback !== undefined) && (callback !== null) && (typeof callback === "function")) || (this._callbackListeners.length > 0))
+ {
+ client.onreadystatechange = function ()
+ {
+ if (client.readyState === 4)
+ {
+ var status = client.status;
+ if (status === 1223)
+ {
+ status = window.PortableRest.HttpStatusCode.NoContent;
+ }
+ var type = client.getResponseHeader("Content-Type");
+
+ if ((type !== null) && (type.indexOf("xml") !== -1) && (client.responseXML !== null) && (client.responseXML !== undefined))
+ {
+ $this._fireCallbackListeners(callback, client.responseXML.firstChild, status);
+ }
+ else if ((type !== null) && (type.indexOf("json") !== -1) && (client.responseText !== null))
+ {
+ var responseObject;
+ try
+ {
+ responseObject = JSON.parse(client.responseText);
+ }
+ catch (error)
+ {
+ $this._fireCallbackListeners(callback, client.responseText, status, error);
+ return;
+ }
+ $this._fireCallbackListeners(callback, responseObject, status);
+ }
+ else
+ {
+ $this._fireCallbackListeners(callback, client.responseText, status);
+ }
+ }
+ };
+ }
+
+ client.send(body);
+ };
+
+})(window);
\ No newline at end of file
diff --git a/src/PortableRestJs/test.aspx b/src/PortableRestJs/test.aspx
new file mode 100644
index 0000000..a669a86
--- /dev/null
+++ b/src/PortableRestJs/test.aspx
@@ -0,0 +1 @@
+<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="PortableRestJs.test" %>
\ No newline at end of file
diff --git a/src/PortableRestJs/test.aspx.cs b/src/PortableRestJs/test.aspx.cs
new file mode 100644
index 0000000..2f59789
--- /dev/null
+++ b/src/PortableRestJs/test.aspx.cs
@@ -0,0 +1,36 @@
+using System;
+using System.IO;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+namespace PortableRestJs
+{
+ public partial class test : System.Web.UI.Page
+ {
+ protected void Page_Load(object sender, EventArgs e)
+ {
+ Response.Clear();
+ string body = string.Empty;
+ using (StreamReader streamReader = new StreamReader(Request.InputStream))
+ {
+ body = streamReader.ReadToEnd();
+ }
+ JObject jObject = null;
+ switch(Request.ContentType)
+ {
+ case "application/json":
+ jObject = JsonConvert.DeserializeObject(body);
+ break;
+ case "application/x-www-form-urlencoded":
+ jObject = new JObject();
+ foreach (string postField in Request.Form.AllKeys)
+ {
+ jObject.AddFirst(new JProperty(postField, Request.Form[postField]));
+ }
+ break;
+ }
+ Response.Write(JsonConvert.SerializeObject(jObject));
+ Response.ContentType = "application/json";
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/PortableRestJs/test.aspx.designer.cs b/src/PortableRestJs/test.aspx.designer.cs
new file mode 100644
index 0000000..cf44240
--- /dev/null
+++ b/src/PortableRestJs/test.aspx.designer.cs
@@ -0,0 +1,15 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace PortableRestJs {
+
+
+ public partial class test {
+ }
+}
diff --git a/src/PortableRestJs/test.html b/src/PortableRestJs/test.html
new file mode 100644
index 0000000..4699ec2
--- /dev/null
+++ b/src/PortableRestJs/test.html
@@ -0,0 +1,86 @@
+
+
+
+
+
+
+
+
+
+
+
+ - JSON Test:
+ - Form Test:
+ - Xml Test:
+
+
+
+
diff --git a/src/PortableRestJs/xmlTest.aspx b/src/PortableRestJs/xmlTest.aspx
new file mode 100644
index 0000000..559e647
--- /dev/null
+++ b/src/PortableRestJs/xmlTest.aspx
@@ -0,0 +1 @@
+<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="xmlTest.aspx.cs" Inherits="PortableRestJs.xmlTest" %>
\ No newline at end of file
diff --git a/src/PortableRestJs/xmlTest.aspx.cs b/src/PortableRestJs/xmlTest.aspx.cs
new file mode 100644
index 0000000..ed5854a
--- /dev/null
+++ b/src/PortableRestJs/xmlTest.aspx.cs
@@ -0,0 +1,26 @@
+using System;
+using System.IO;
+using System.Xml.Linq;
+using Newtonsoft.Json;
+
+namespace PortableRestJs
+{
+ public partial class xmlTest : System.Web.UI.Page
+ {
+ protected void Page_Load(object sender, EventArgs e)
+ {
+ Response.Clear();
+ string body = string.Empty;
+ using (StreamReader streamReader = new StreamReader(Request.InputStream))
+ {
+ body = streamReader.ReadToEnd();
+ }
+
+ XDocument xDoc = JsonConvert.DeserializeXNode(body);
+
+ Response.Write(xDoc.ToString(SaveOptions.DisableFormatting));
+ Response.ContentType = "application/xml";
+ Response.Headers.Add("Content-Type", Response.ContentType);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/PortableRestJs/xmlTest.aspx.designer.cs b/src/PortableRestJs/xmlTest.aspx.designer.cs
new file mode 100644
index 0000000..4a6a324
--- /dev/null
+++ b/src/PortableRestJs/xmlTest.aspx.designer.cs
@@ -0,0 +1,15 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace PortableRestJs {
+
+
+ public partial class xmlTest {
+ }
+}