-
May 28th, 2018, 09:20 AM
#1
Thread Starter
New Member
how to view the contents of post data via API_KEY
Code:
Imports System.Net
Imports System.Web.Script.Serialization
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Imports System.Text
Imports System.IO
Imports System.Security.Cryptography
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lstType.Items.Add("buy")
lstType.Items.Add("sell")
lstpair.Items.Add("ltc_idr")
lstpair.Items.Add("ltc_btc")
lstpair.Items.Add("btc_idr")
lstmeth.Items.Add("Trade")
End Sub
Private Function StringToSHA512(ByVal content As String) As String
Dim M5 As New SHA512Managed
Dim bytestring() As Byte = Encoding.UTF8.GetBytes(content)
bytestring = M5.ComputeHash(bytestring)
Dim signer As String = Nothing
For Each bt As Byte In bytestring
signer &= bt.ToString("x2")
Next
Return signer
End Function
Private Function GetUnixTimestamp(ByVal currDate As DateTime) As Double
'create Timespan by subtracting the value provided from the Unix Epoch
Dim span As TimeSpan = (currDate - New DateTime(2018, 1, 1, 0, 0, 0, 0).ToLocalTime())
'return the total seconds (which is a UNIX timestamp)
Return span.TotalSeconds
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim postData As String
Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://indodax.com/tapi"), HttpWebRequest)
Dim randomn As String
Dim keyer As String = LCase("API_KEY") 'your key goes here
Dim secret As String = "SECREET_KEY" 'your secret goes here
randomn = GetUnixTimestamp(Now)
postData = ' HOW TO USE SOURCE IN POST DATA ????????????????????????????????????????
'postData = randomn
Dim KeyByte() As Byte = Encoding.ASCII.GetBytes(secret)
Dim HMAcSha As New HMACSHA512(Encoding.ASCII.GetBytes(secret))
Dim messagebyte() As Byte = Encoding.ASCII.GetBytes(postData)
Dim hashmessage() As Byte = HMAcSha.ComputeHash(messagebyte)
Dim Sign As String = BitConverter.ToString(hashmessage)
Sign = Sign.Replace("-", "")
postReq.Method = "POST"
postReq.KeepAlive = False
postReq.Headers.Add("Key", keyer)
postReq.Headers.Add("Sign", LCase(Sign))
postReq.ContentType = "application/x-www-form-urlencoded"
postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
postReq.ContentLength = messagebyte.Length
Dim postreqstream As Stream = postReq.GetRequestStream()
postreqstream.Write(messagebyte, 0, messagebyte.Length)
postreqstream.Close()
Dim postresponse As HttpWebResponse
postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
Dim postreqreader As New StreamReader(postresponse.GetResponseStream())
Dim thepage As String = postreqreader.ReadToEnd
'thepage = thepage.Replace(Chr(34), Chr(39))
MsgBox(thepage)
End Sub
Last edited by Shaggy Hiker; May 28th, 2018 at 09:54 AM.
Reason: Added CODE tags.
-
May 28th, 2018, 09:51 AM
#2
Re: how to view the contents of post data via API_KEY
Please use appropriate formatting tags when posting code:
vb.net Code:
Imports System.Net Imports System.Web.Script.Serialization Imports Newtonsoft.Json Imports Newtonsoft.Json.Linq Imports System.Text Imports System.IO Imports System.Security.Cryptography Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load lstType.Items.Add("buy") lstType.Items.Add("sell") lstpair.Items.Add("ltc_idr") lstpair.Items.Add("ltc_btc") lstpair.Items.Add("btc_idr") lstmeth.Items.Add("Trade") End Sub Private Function StringToSHA512(ByVal content As String) As String Dim M5 As New SHA512Managed Dim bytestring() As Byte = Encoding.UTF8.GetBytes(content) bytestring = M5.ComputeHash(bytestring) Dim signer As String = Nothing For Each bt As Byte In bytestring signer &= bt.ToString("x2") Next Return signer End Function Private Function GetUnixTimestamp(ByVal currDate As DateTime) As Double 'create Timespan by subtracting the value provided from the Unix Epoch Dim span As TimeSpan = (currDate - New DateTime(2018, 1, 1, 0, 0, 0, 0).ToLocalTime()) 'return the total seconds (which is a UNIX timestamp) Return span.TotalSeconds End Function Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim postData As String Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://indodax.com/tapi"), HttpWebRequest) Dim randomn As String Dim keyer As String = LCase("API_KEY") 'your key goes here Dim secret As String = "SECREET_KEY" 'your secret goes here randomn = GetUnixTimestamp(Now) postData = ' HOW TO USE SOURCE IN POST DATA ???????????????????????????????????????? 'postData = randomn Dim KeyByte() As Byte = Encoding.ASCII.GetBytes(secret) Dim HMAcSha As New HMACSHA512(Encoding.ASCII.GetBytes(secret)) Dim messagebyte() As Byte = Encoding.ASCII.GetBytes(postData) Dim hashmessage() As Byte = HMAcSha.ComputeHash(messagebyte) Dim Sign As String = BitConverter.ToString(hashmessage) Sign = Sign.Replace("-", "") postReq.Method = "POST" postReq.KeepAlive = False postReq.Headers.Add("Key", keyer) postReq.Headers.Add("Sign", LCase(Sign)) postReq.ContentType = "application/x-www-form-urlencoded" postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)" postReq.ContentLength = messagebyte.Length Dim postreqstream As Stream = postReq.GetRequestStream() postreqstream.Write(messagebyte, 0, messagebyte.Length) postreqstream.Close() Dim postresponse As HttpWebResponse postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse) Dim postreqreader As New StreamReader(postresponse.GetResponseStream()) Dim thepage As String = postreqreader.ReadToEnd 'thepage = thepage.Replace(Chr(34), Chr(39)) MsgBox(thepage) End Sub
Also, please provide a FULL and CLEAR explanation of the problem. A title and a wad of code isn't really sufficient. An explanation and the relevant code is what you should post.
-
May 28th, 2018, 09:58 AM
#3
Re: how to view the contents of post data via API_KEY
I edited your post to add [CODE][/CODE] tags. You can do this by pressing the # button and pasting the code between the tags. If you want the formatting that JM showed, you can use the VB tag.
What's happening with the code? I'm on the wrong platform to compare it to a sample I have that is working, but one thing I can say is that you need to use some exception handling for this. Some errors come back from web requests, and you often want to catch and handle the errors, since they are often very important to understanding what is happening.
My usual boring signature: Nothing
-
May 28th, 2018, 10:01 AM
#4
Thread Starter
New Member
Re: how to view the contents of post data via API_KEY
well, before i just joined in this forum .. i am confused to make the appropriate format apologize for that mistake ..
I have a problem displaying the result of postdata called by apikey and seccret key ..
what steps should I enter on the postdata in:
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim postData As String
Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://indodax.com/tapi"), HttpWebRequest)
Dim randomn As String
Dim keyer As String = LCase("AHWXZ7NR-0UWANYZ7-KIRFAFO7-POJYOSSH-L3KA5UHY") 'your key goes here
Dim secret As String = "e7ac391cf63ee0b2e0b51257d0262e9a46edcc380b533c831bba418a9d6d7ba2c69946e45a2b3702" 'your secret goes here
randomn = GetUnixTimestamp(Now)
postData =
Code:
WHAT I CAN USE SOURCE IN THIS POSTDATA???
Dim KeyByte() As Byte = Encoding.ASCII.GetBytes(secret)
Dim HMAcSha As New HMACSHA512(Encoding.ASCII.GetBytes(secret))
Dim messagebyte() As Byte = Encoding.ASCII.GetBytes(postData)
Dim hashmessage() As Byte = HMAcSha.ComputeHash(messagebyte)
Dim Sign As String = BitConverter.ToString(hashmessage)
Sign = Sign.Replace("-", "")
postReq.Method = "POST"
postReq.KeepAlive = False
postReq.Headers.Add("Key", keyer)
postReq.Headers.Add("Sign", LCase(Sign))
postReq.ContentType = "application/x-www-form-urlencoded"
postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
postReq.ContentLength = messagebyte.Length
Dim postreqstream As Stream = postReq.GetRequestStream()
postreqstream.Write(messagebyte, 0, messagebyte.Length)
postreqstream.Close()
Dim postresponse As HttpWebResponse
postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
Dim postreqreader As New StreamReader(postresponse.GetResponseStream())
Dim thepage As String = postreqreader.ReadToEnd
thepage = thepage.Replace(Chr(34), Chr(39))
MsgBox(thepage)
End Sub
-
May 28th, 2018, 10:03 AM
#5
Thread Starter
New Member
Re: how to view the contents of post data via API_KEY
well, before i just joined in this forum .. i am confused to make the appropriate format apologize for that mistake ..
I have a problem displaying the result of postdata called by apikey and seccret key ..
what steps should I enter on the postdata in:
postData = ' HOW TO USE SOURCE IN POST DATA ????????????????????????????????????????
-
May 28th, 2018, 10:47 AM
#6
Re: how to view the contents of post data via API_KEY
I misunderstood the question. I thought you were trying to add the API key, but it looks like you've done that right.
What are you getting back? Without exception handling, if you did something wrong, that function is just going to crash. Whether you catch the exception elsewhere or not, I can't say, but if you are not getting an exception, then what are you getting? What you have written looks correct, so if you are not getting an exception, you should be seeing something in the messagebox.
Probably better than a messagebox would be to put a breakpoint in the code somewhere prior to the request and step through the request to see what you are getting back, but whatever it is should show up in the messagebox, as you have it.
My usual boring signature: Nothing
-
May 28th, 2018, 10:52 AM
#7
Thread Starter
New Member
Re: how to view the contents of post data via API_KEY
Alhamdulillah..
I have got it after I try it using the header method ...
Many thanks have responded ...
-
May 28th, 2018, 10:57 AM
#8
Thread Starter
New Member
Re: how to view the contents of post data via API_KEY
Code:
Dim postData As String
Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://indodax.com/tapi"), HttpWebRequest)
Dim randomn As String
Dim keyer As String = LCase("API_KEY") 'your key goes here
Dim secret As String = "SECREET_KEY" 'your secret goes here
randomn = GetUnixTimestamp(Now)
postData = "method=" & lstmeth.SelectedItem & "&nonce=" & randomn & "&pair=" & lstpair.SelectedItem & "&type=" & lstType.SelectedItem & "&idr=" & txtrate.Text & "&price=" & txtamount.Text
Dim KeyByte() As Byte = Encoding.ASCII.GetBytes(secret)
Dim HMAcSha As New HMACSHA512(Encoding.ASCII.GetBytes(secret))
Dim messagebyte() As Byte = Encoding.ASCII.GetBytes(postData)
Dim hashmessage() As Byte = HMAcSha.ComputeHash(messagebyte)
Dim Sign As String = BitConverter.ToString(hashmessage)
Sign = Sign.Replace("-", "")
postReq.Method = "POST"
postReq.KeepAlive = False
postReq.Headers.Add("Key", keyer)
postReq.Headers.Add("Sign", LCase(Sign))
postReq.ContentType = "application/x-www-form-urlencoded"
postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
postReq.ContentLength = messagebyte.Length
Dim postreqstream As Stream = postReq.GetRequestStream()
postreqstream.Write(messagebyte, 0, messagebyte.Length)
postreqstream.Close()
Dim postresponse As HttpWebResponse
postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
Dim postreqreader As New StreamReader(postresponse.GetResponseStream())
Dim thepage As String = postreqreader.ReadToEnd
thepage = thepage.Replace(Chr(34), Chr(39))
MsgBox(thepage)
Last edited by Shaggy Hiker; May 28th, 2018 at 11:40 AM.
-
May 28th, 2018, 11:42 AM
#9
Re: how to view the contents of post data via API_KEY
So, it's all working now? That's good, cause it looked like you were close.
I'd still suggest wrapping the code in a Try...Catch block. Loads of simple issues can be returned as exceptions from web requests. Without exception handling, if their server goes down your code would likely just crash.
However, if the question is resolved, please go to Thread Tools and mark it resolved. I see that you already put a checkmark on it, which is pretty close.
My usual boring signature: Nothing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|