Whew! I finally found my post issue, and only took me four days! I now know more than I ever wanted to know about post requests. My problem turned out to be a head slapper, I was sending cryptsy capital Hex instead of lower case. It makes sense, a capital "A" uses a different byte than a lower case "a", still I wish the receiving end had programming to accept either. I also learned that it is hard to get your wife and children to share in the excitement of a website accepting your first post request.
Here is the code:
Libraries: ByteConverter, Encryption, HTTP, HttpUtils2, StringFunctions
Code:
Sub Globals
Dim sf As StringFunctions
Dim job_GetInfo As HttpJob
Dim API_Key, API_Secret, API_Signed As String
Dim Post_URL, Post_Data As String
Dim Byte_Conv As ByteConverter
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
sf.Initialize
End If
Post_URL = "https://api.cryptsy.com/api"
API_Key = "0123456789abcdef0123456789abcdef01234567"
API_Secret = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
Post_Data = "method=getinfo&nonce=1"
Dim Sign() As Byte = HashHmac(Post_Data, API_Secret)
API_Signed = Byte_Conv.HexFromBytes(Sign) 'convert to HEX
API_Signed = sf.Lower(API_Signed) 'convert to lower hex
Get_Job
End Sub
Sub Get_Job
Dim job_GetInfo As HttpJob
job_GetInfo.Initialize("job_GetInfo", Me)
job_GetInfo.PostString(Post_URL, Post_Data)
job_GetInfo.GetRequest.SetHeader("Sign", API_Signed)
job_GetInfo.GetRequest.SetHeader("Key", API_Key)
'Stuff that appears unnecessary but since others use it.....
job_GetInfo.GetRequest.SetHeader("User-Agent","Mozilla/4.0 (compatible; Cryptsy API B4A client)")
job_GetInfo.GetRequest.SetContentType("application/x-www-form-urlencoded")
End Sub
Sub JobDone(job As HttpJob)
Log("JobName = " & job.JobName & ", Success = " & job.Success)
If job.Success = True Then
Select job.JobName
Case "job_GetInfo"
'print the result to the logs
Log(job.GetString)
End Select
Else
Log("Error: " & job.ErrorMessage)
ToastMessageShow("Error: " & job.ErrorMessage, True)
End If
job.Release
End Sub
Sub HashHmac(data As String, secret As String) As Byte()
Dim m As Mac 'm As Message Authentication Code
Dim kg As KeyGenerator 'kg As KeyGenerator
kg.Initialize("HmacSHA512") 'initialize kg using HmacSHA512 algorithm
kg.KeyFromBytes(secret.GetBytes("UTF8")) 'encode string "secret" to an array of Bytes using UTF8
m.Initialise("HmacSHA512", kg.Key) 'initialize m using HmacSHA512 algorithm and the secret key
m.Update(data.GetBytes("UTF8")) 'encodes post data to an array of Bytes and loads it to be signed
Return m.Sign 'sign the loaded data using the secret key, return the calc signature data
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
I'm currently always using nonce = 1 and it is working but I will use some sort of time stamp later. I think cryptsy wants it in the form of an integer.
Thanks to Erel and DonManfred for the help!