Author Topic: Pastebin  (Read 1419 times)

MrTAToad

  • Guest
Pastebin
« on: 2011-Apr-06 »
The following code sends test to Pastebin :

Code: (glbasic) [Select]
DEBUG "Output : "+HttpPost$("","pastebin.com","/api/api_post.php",80,"----------------bOunDarY-------"+INTEGER(GETTIMERALL()*1000.0)+"-"+RND(99999)+"--","api_option=paste&api_dev_key=???&api_paste_code=test")
Code: (glbasic) [Select]
// ---------------------------------------------------------------------
// Send a HTTP POST Request and return what the webbrowser would display
// ---------------------------------------------------------------------
FUNCTION HttpPost$: proxy$, server$, curl$, port%, boundary$, postdata$
LOCAL header$ // the HTTP post header

// Fix proxy urls
IF LEN(proxy$)
curl$ = "http://"+server$+curl$
server$ = proxy$
ENDIF

// end post data
//postdata$ = postdata$ + "--"+boundary$+"--"

LOCAL send$
send$ = "POST "+curl$+" HTTP/1.0\r\n"
INC send$, "User-Agent: GLBasic\r\n"
INC send$, "Host:"+server$+"\r\n"
INC send$, "Accept: */*\r\n"
INC send$, "Content-Type: application/x-www-form-urlencoded, boundary="+boundary$+"\r\n"
INC send$, "Content-Length: "+LEN(postdata$) + "\r\n"
INC send$, "\r\n"
INC send$, postdata$

DEBUG "Sending : "+send$+"\n"
KEYWAIT
LOCAL sock%, file$
SOCK_INIT()
sock% = SOCK_TCPCONNECT(server$, port%)
IF SOCK_TCPSEND(sock%, send$) > 0
LOCAL chunk$, rv%
WHILE TRUE
chunk$=""
rv% = SOCK_RECV(sock%, chunk$, 1024)
SELECT rv%
CASE -1
DEBUG NETGETLASTERROR$()+"\n"
file$=""
BREAK
CASE -2 // non blocking socket not would block
SLEEP 5
CASE 0
BREAK // ok, reading is done
CASE >0
INC file$, chunk$
ENDSELECT
WEND
// jippieh! We got a response

// split HTTP header and actual file information apart
LOCAL pos%
pos = INSTR(file$, "\r\n\r\n")
IF pos>=0
header$ = MID$(file$, 0, pos%)
file$   = MID$(file$, pos%+4)
ELSE
header$=""
ENDIF
ENDIF
SOCK_CLOSE(sock%)

RETURN file$
ENDFUNCTION

You do need your own developer API key though.

The output I get is :

Code: (glbasic) [Select]
http://pastebin.com/b3vZ2e4v