Results 1 to 9 of 9

Thread: how to view the contents of post data via API_KEY

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2018
    Posts
    6

    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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: how to view the contents of post data via API_KEY

    Please use appropriate formatting tags when posting code:
    vb.net Code:
    1. Imports System.Net
    2. Imports System.Web.Script.Serialization
    3. Imports Newtonsoft.Json
    4. Imports Newtonsoft.Json.Linq
    5. Imports System.Text
    6. Imports System.IO
    7. Imports System.Security.Cryptography
    8.  
    9.  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    10.         lstType.Items.Add("buy")
    11.         lstType.Items.Add("sell")
    12.         lstpair.Items.Add("ltc_idr")
    13.         lstpair.Items.Add("ltc_btc")
    14.         lstpair.Items.Add("btc_idr")
    15.         lstmeth.Items.Add("Trade")
    16.     End Sub
    17.     Private Function StringToSHA512(ByVal content As String) As String
    18.         Dim M5 As New SHA512Managed
    19.         Dim bytestring() As Byte = Encoding.UTF8.GetBytes(content)
    20.         bytestring = M5.ComputeHash(bytestring)
    21.         Dim signer As String = Nothing
    22.         For Each bt As Byte In bytestring
    23.             signer &= bt.ToString("x2")
    24.         Next
    25.         Return signer
    26.     End Function
    27.  
    28.     Private Function GetUnixTimestamp(ByVal currDate As DateTime) As Double
    29.         'create Timespan by subtracting the value provided from the Unix Epoch
    30.         Dim span As TimeSpan = (currDate - New DateTime(2018, 1, 1, 0, 0, 0, 0).ToLocalTime())
    31.         'return the total seconds (which is a UNIX timestamp)
    32.         Return span.TotalSeconds
    33.     End Function
    34.  
    35.  
    36.  
    37.  
    38.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    39.         Dim postData As String
    40.  
    41.         Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://indodax.com/tapi"), HttpWebRequest)
    42.         Dim randomn As String
    43.         Dim keyer As String = LCase("API_KEY") 'your key goes here
    44.         Dim secret As String = "SECREET_KEY" 'your secret goes here
    45.         randomn = GetUnixTimestamp(Now)
    46.  
    47.         postData =  ' HOW TO USE SOURCE IN POST DATA ????????????????????????????????????????
    48.  
    49.         'postData = randomn
    50.         Dim KeyByte() As Byte = Encoding.ASCII.GetBytes(secret)
    51.         Dim HMAcSha As New HMACSHA512(Encoding.ASCII.GetBytes(secret))
    52.         Dim messagebyte() As Byte = Encoding.ASCII.GetBytes(postData)
    53.         Dim hashmessage() As Byte = HMAcSha.ComputeHash(messagebyte)
    54.  
    55.         Dim Sign As String = BitConverter.ToString(hashmessage)
    56.         Sign = Sign.Replace("-", "")
    57.  
    58.         postReq.Method = "POST"
    59.         postReq.KeepAlive = False
    60.         postReq.Headers.Add("Key", keyer)
    61.         postReq.Headers.Add("Sign", LCase(Sign))
    62.  
    63.         postReq.ContentType = "application/x-www-form-urlencoded"
    64.         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)"
    65.         postReq.ContentLength = messagebyte.Length
    66.  
    67.  
    68.         Dim postreqstream As Stream = postReq.GetRequestStream()
    69.         postreqstream.Write(messagebyte, 0, messagebyte.Length)
    70.         postreqstream.Close()
    71.         Dim postresponse As HttpWebResponse
    72.  
    73.         postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
    74.  
    75.         Dim postreqreader As New StreamReader(postresponse.GetResponseStream())
    76.  
    77.         Dim thepage As String = postreqreader.ReadToEnd
    78.         'thepage = thepage.Replace(Chr(34), Chr(39))
    79.  
    80.         MsgBox(thepage)
    81.  
    82.  
    83.     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.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,047

    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

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2018
    Posts
    6

    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

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2018
    Posts
    6

    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 ????????????????????????????????????????

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,047

    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

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2018
    Posts
    6

    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 ...

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2018
    Posts
    6

    Resolved 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.

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,047

    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
  •  



Click Here to Expand Forum to Full Width