Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CLIENT REQUEST
- function httpBuildQuery(data){
- var ret=[];
- for(var d in data)ret.push(encodeURIComponent(d)+"="+encodeURIComponent(data[d]));
- return ret.join("&");
- }
- function shortenUrls(urls=[],callback=function(shortUrls){}){
- //building request json
- var request={data:[],defult:{
- type:"POST",
- url:"http://tinyurl.com/create.php"
- }};
- for(var i=0;i<urls.length;i++){
- request.data[i]={
- post:httpBuildQuery({
- url:urls[i],
- submit:"Make TinyURL!",
- alias:""
- })};
- }
- //http://lapissea.byethost8.com/common/GetURLContent.js
- GetURLContent.post("/common/SameDomainProxy.php",JSON.stringify(request),function(txt){
- txt=JSON.parse(txt);
- if(typeof testingHTML==="undefined")testingHTML=document.createElement('html');
- var shortURLs=[];
- for(var i=0;i<txt.length;i++){
- testingHTML.innerHTML=txt[0];
- shortURLs[i]=testingHTML.querySelector("#contentcontainer").querySelector("a").href;
- }
- callback(shortURLs);
- });
- }
- //SERVER
- <?php
- /*
- Usage: json in post
- {
- data:[
- {
- type:"get/post/head",
- url:"http://www.pornhub.com/",
- post:"GIVE ME THAT PUSSY"
- },
- {
- post:"GIVE ME THAT PUSSY2"
- },
- {
- post:"GIVE ME THAT PUSSY3"
- },
- ...
- ],
- defult:{ //defult fills missing spots in data
- type:"get/post/head",
- url:"http://www.pornhub.com/"
- }
- }
- */
- $data=json_decode(file_get_contents("php://input"));
- if(!is_array($data->data))respond("request.data is not an array!");
- $def=$data->defult;
- $responses=[];
- for($i=0;$i<count($data->data);$i++){
- $d=$data->data[$i];
- $type=isset($d->type)?$d->type:$def->type;
- $type=strtolower($type);
- $url=isset($d->url)?$d->url:$def->url;
- if($type=="post")$responses[$i]=postRrq($url,isset($d->post)?$d->post:$def->post);
- else if($type=="get")$responses[$i]=file_get_contents($url);
- else if($type=="head")$responses[$i]=get_headers($url,1);
- else $responses[$i]='"'.$type.'" is an invalid type!';
- }
- respond($responses);
- function postRrq($url,$post){
- $options=[
- 'http'=>[
- 'header' =>"Content-type: application/x-www-form-urlencoded\r\n",
- 'method' =>'POST',
- 'content'=>$post
- ]
- ];
- $context =stream_context_create($options);
- $result=file_get_contents($url, false, $context);
- return $result;
- }
- function respond($obj){
- echo json_encode($obj);
- exit;
- }
- ?>
Add Comment
Please, Sign In to add comment