Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Jul 20, 2017 11:51 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Uploading files with HTTPSocket.Post
PostPosted: Fri Jan 18, 2013 6:30 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
I've been banging my head against this for some time, yet nothing I do seems to work.

I'm trying to use an HTTPSocket to upload a file to VirusTotal.com using their public API. The relevant part of their (skanty) documentation is here: https://www.virustotal.com/documentatio ... ning-files

My code:
Private Sub SubmitFile(File As FolderItem, APIkey As String)
Const MIMEBoundary = "--------0xKhTmLMIMEBoundary"
Dim CRLF As String = Encodings.ASCII.Chr(13) + Encodings.ASCII.Chr(10)
Dim sock As New HTTPSocket

dim stream as BinaryStream
dim postContent as String
postContent = postContent + "--" + MIMEBoundary + crlf
postContent = postContent + "Content-Disposition: form-data; name=""file"""
postContent = postContent + "; filename=""" + file.AbsolutePath + """"
postContent = postContent + crlf + "Content-Type: application/binary" + crlf + crlf
stream = stream.Open(File)
postContent = postContent + stream.Read( file.length )
stream.close
postContent = postContent + crlf
postContent = postContent + "--" + MIMEBoundary + crlf
postContent = postContent + "Content-Disposition: form-data; name=""apikey"""
postContent = postContent + crlf + "Content-Type: text/plain" + crlf + crlf
postContent = postContent + APIkey
postContent = postContent + crlf
postContent = postContent + "--" + MIMEBoundary + "--"

sock.SetPostContent(postContent, "multipart/form-data, boundary=" + MIMEBoundary)
Dim s As String = Sock.Post("www.virustotal.com/vtapi/v2/file/scan", 5)
Break
End Sub


I get an HTTP 403 error. Any suggestions?

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: Uploading files with HTTPSocket.Post
PostPosted: Fri Jan 18, 2013 6:51 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
Quote:
A web server may return a 403 Forbidden HTTP status code in response to a request from a client for a web page or resource to indicate that the server refuses to allow the requested action. In other words, the server can be reached, but the server declined to allow the requested access.



So I'd say your creditials are incorrect

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Uploading files with HTTPSocket.Post
PostPosted: Fri Jan 18, 2013 7:02 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
The API key is valid; all other API calls work, but no other API calls involve uploading a file.

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: Uploading files with HTTPSocket.Post
PostPosted: Fri Jan 18, 2013 8:32 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
Hi charonn0

I think Dave answered pretty well but I'll shed more light on it.

I know 403 errors when the server's file permissions are set to NOT allow public access to the file(s) in question.


Assuming your code and their API directions are correct (I didn't check) :

This is not something you as the client can correct. It requires server access to change permission settings which allow you the client access.


If your API code is not correct, then correct it :)

You may want to get an HTTPsocket to upload a file to your own server using php first to make sure your boundaries are correct, etc.


There might be a thread on this in the networking section.

I would offer more help but I'm totally swamped; Not only am I behind my own production schedule but I got suckered into making a website / online business for a family member for free :(

Ps. I really want to WE to be working reliably !
Doing this stuff in php, CSS, HTML, etc. is boring and takes me a long time!!!!

Gotta look more at WE soon and put it to the test.


Top
 Profile  
Reply with quote  
 Post subject: Re: Uploading files with HTTPSocket.Post
PostPosted: Sat Jan 19, 2013 6:08 pm 
Offline

Joined: Fri Nov 16, 2007 10:18 pm
Posts: 195
Location: Portland, OR
I notice that you are passing the absolute path in the filename parameter. This is generally not allowed. Try file.Name instead.

_________________
Windows: Win7 64bit sp1, Vista 32bit sp2, WinXP 32bit SP3
Linux: RH EL6
Mac: Died in 2011 and took 2 months to notice.

RealStudio: 2012r2


Top
 Profile  
Reply with quote  
 Post subject: Re: Uploading files with HTTPSocket.Post
PostPosted: Sat Jan 19, 2013 6:13 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
Good point, but by itself doesn't seem to help.

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: Uploading files with HTTPSocket.Post
PostPosted: Mon Jan 21, 2013 12:47 am 
Offline

Joined: Sat May 26, 2007 11:37 pm
Posts: 52
Location: Tumwater, Wa
Hey charonn0,

I spotted this in the link that was posted,

Quote:
If you try to perform calls to functions for which you do not have the required privileges an HTTP Error 403 Forbidden is raised.


is there a way to check your privilege level?

_________________
• program, n.: A magic spell cast over a computer allowing it to turn one's input into error messages.
tr.v. To engage in a pastime similar to banging one's head against a wall, but with fewer opportunities for reward


Top
 Profile  
Reply with quote  
 Post subject: Re: Uploading files with HTTPSocket.Post
PostPosted: Mon Jan 21, 2013 1:19 am 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
My privilege level is (AFAIK) the same as everyone else using the public API, which supports uploads.

I have the feeling that I'm getting the 403 error because the API key is not being encoded in the Post request properly. This is the only request I need to hand-roll, so my instinct is that I'm just doing it wrongly.

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: Uploading files with HTTPSocket.Post
PostPosted: Mon Jan 21, 2013 4:50 am 
Offline

Joined: Mon May 31, 2010 5:35 am
Posts: 2412
Location: Netherlands
You forget 1 thing.

That is to use HTTPSecureSocket instead of HTTPSocket

the docs say:
Quote:
In order to send a file you must perform an HTTP POST request to the following URL:

https://www.virustotal.com/vtapi/v2/file/scan

_________________
SWORT™
- Windows Vista, Windows XP, Windows 7, Linux Mint 11 and Mac OSX Lion
- REAL Studio Enterprise(latest) and WEB Edition(latest)
- Plugins (MBS Complete, ToringoLib, Einhugur, VanHoek + Some open source plugins)
For Dutch User Groups ask me to enter!


Top
 Profile  
Reply with quote  
 Post subject: Re: Uploading files with HTTPSocket.Post
PostPosted: Mon Jan 21, 2013 5:30 am 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
It also specifies "API URLs are HTTPS (although you can use traditional HTTP if you wish)"

I intend to use HTTPS once I've sorted out the upload problem; I'm using plain HTTP right now so I can capture the packets being sent to see what the server is actually getting.

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: Uploading files with HTTPSocket.Post
PostPosted: Mon Jan 21, 2013 5:39 am 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
Sock.Post("www.virustotal.com/vtapi/v2/file/scan", 5)


What does the #5 in the sock string mean just out of curiosity?

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: Uploading files with HTTPSocket.Post
PostPosted: Mon Jan 21, 2013 2:49 pm 
Offline

Joined: Mon May 31, 2010 5:35 am
Posts: 2412
Location: Netherlands
charonn0 wrote:
It also specifies "API URLs are HTTPS (although you can use traditional HTTP if you wish)"

I intend to use HTTPS once I've sorted out the upload problem; I'm using plain HTTP right now so I can capture the packets being sent to see what the server is actually getting.


Perhaps they mean non-authenticated api parts.
I won't think they let you do any login on http based api parts.

_________________
SWORT™
- Windows Vista, Windows XP, Windows 7, Linux Mint 11 and Mac OSX Lion
- REAL Studio Enterprise(latest) and WEB Edition(latest)
- Plugins (MBS Complete, ToringoLib, Einhugur, VanHoek + Some open source plugins)
For Dutch User Groups ask me to enter!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group