Skip to content
Snippets Groups Projects
Commit 1ca26faf authored by deuce's avatar deuce
Browse files

Add POST support and returning response headers to the script.

parent 69527201
Branches
Tags
No related merge requests found
......@@ -44,6 +44,23 @@ function HTTPRequest()
this.AddDefaultHeaders();
};
this.SetupPost=function(url, referer, base, data) {
this.referer=referer;
this.base=base;
this.url=new URL(url, this.base);
if(this.url.scheme!='http')
throw("Unknown scheme! '"+this.url.scheme+"'");
if(this.url.path=='')
this.url.path='/';
if(this.url.query != '');
this.request="POST "+this.url.request_path+" HTTP/1.0";
this.request_headers=[];
this.AddDefaultHeaders();
this.body=data;
this.request_headers.push("Content-Type: application/x-www-form-urlencoded");
this.request_headers.push("Content-Length: "+data.length);
};
this.SendRequest=function() {
var i;
......@@ -82,6 +99,7 @@ function HTTPRequest()
throw("Unable to receive headers");
if(header=='')
return;
this.response_headers.push(header);
m=header.match(/^Content-length:\s+([0-9]+)$/);
if(m!=null)
this.contentlength=parseInt(m[0]);
......@@ -109,4 +127,11 @@ function HTTPRequest()
this.ReadResponse();
return(this.body);
};
this.Post=function(url, data, referer, base) {
this.SetupPost(url,referer,base,data);
this.SendRequest();
this.ReadResponse();
return(this.body);
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment