GDAX Post API not working VB.net I am having trouble with a (400) bad request on POST requests.  I am able to execute all Get and Delete requests with the same signature process, but obviously the body is string.empty. We have tested all sorts of different JSON formatting to try and get this to work, but it is not working. We have not been able to find an example of ANY prehash signature to compare to.  Also, unless the POST server time is different than the GET and DELETE server times we have the correct timestamp as we are within 1 second of the GET/time API call for server time.  GDAX allows for 30 second buffer to authenticate.

Public Shared Function placeOrder()
    Try
        Dim Body As String = "{""type"":""limit"",""side"":""sell"",""product_id"":""BTC-USD"",""price"":""20000"",""size\"":""0.02235229""}"
        Dim ts As String = GetNonce()
        Dim method As String = "/orders"
        Dim str_GDAX_Main As String = "https://api.gdax.com"
        Dim sig As String = GetSignature(ts, "POST", method, Body)
        Dim fr As System.Net.HttpWebRequest
        Dim targetURI As New Uri(str_GDAX_Main &amp; method)
        'Dim response As String

        Dim jsonDataBytes As Byte() = Encoding.UTF8.GetBytes(Body)


        fr = DirectCast(HttpWebRequest.Create(targetURI), System.Net.HttpWebRequest)
        fr.Headers.Add("CB-ACCESS-KEY", config_API_Key)
        fr.Headers.Add("CB-ACCESS-SIGN", sig)
        fr.Headers.Add("CB-ACCESS-TIMESTAMP", ts)
        fr.Headers.Add("CB-ACCESS-PASSPHRASE", config_API_Passphrase)
        fr.UserAgent = UserAgent
        fr.Accept = "application/json"
        fr.Method = "POST"
        fr.ContentLength = jsonDataBytes.Length

        Dim stream = fr.GetRequestStream()
        stream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
        stream.Close()

        Dim response = fr.GetResponse().GetResponseStream()

        Dim reader As New StreamReader(response)
        Dim res = reader.ReadToEnd()
        reader.Close()
        response.Close()
        Return res

        'If (fr.GetResponse().ContentLength &gt; 0) Then
        '    Dim str As New System.IO.StreamReader(fr.GetResponse().GetResponseStream())
        '    response = (str.ReadToEnd())
        '    str.Close()
        'End If

        'Form1.RichTextBox1.Text = (response)
    Catch ex As System.Net.WebException
        MessageBox.Show(ex.Message)
        'Error in accessing the resource, handle it
    End Try
End Function

Public Shared Function GetNonce() As String
    Return (DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds.ToString()
End Function

Public Shared Function GetSignature(nonce As String, method As String, url As String, body As String) As String
    Dim message As String = String.Concat(nonce, method.ToUpper(), url, body)
    Dim encoding = New ASCIIEncoding()
    Dim keyByte As Byte() = Convert.FromBase64String(config_API_Secret)
    Dim messageBytes As Byte() = encoding.GetBytes(message)
    Using hmacsha256 = New HMACSHA256(keyByte)
        Dim hashmessage As Byte() = hmacsha256.ComputeHash(messageBytes)
        Return Convert.ToBase64String(hashmessage)
    End Using
End Function


We have no idea if our body is incorrect or if the URI is incorrect or what the problem is.  If someone can take a look at it and figure out where our body syntax error is.  Or if we should look elsewhere.
your "Public Shared Function GetSignature" works fine! I have been racking my head for a couple of days writing my own but with no luck! Thanks for your snippet!

As far as your problem someone may have already answered it.

To troubleshoot further problems I recommend after you get an HTTP Error to continue your stream and GDAX will give you helpful information.

here is how I handle a web exception.

          Catch ex As WebException

        Dim output As New ClassWebRequestOutput
        output._ErrorMessage = ex.Message.ToString

        Dim exResponse As String
        output._Error = True

        exResponse = New StreamReader(ex.Response.GetResponseStream()).ReadToEnd
        output._Resopnse = exResponse

        Return output
        Exit Function


This continues the web connection with helpful hints.