How to make POST request on C# to blockr.io

0 votes

Trying to write a method to push a TX. 

According to the documentation from blockr, I'm supposed to do this:

To publish a transaction make a POST (!) request with your transaction hex to the push API.

Using curl this would be like (shell example):

curl -d '{"hex":"TX_HASH"}' http://btc.blockr.io/api/v1/tx/push

I am using the following C# code:

Post("http://btc.blockr.io/api/v1/tx/push", "hex", HexString);


    public static void Post(string RequestURL, string Post1, string Post2)
    {
        using (var wb = new WebClient())
        {
            var data = new NameValueCollection();
            data[Post1] = Post2;
            var response = wb.UploadValues(RequestURL, "POST", data);
        }
    }

But i get a lot of errors

Aug 30, 2018 in Blockchain by slayer
• 29,170 points
526 views

1 answer to this question.

0 votes

By default UploadValues doesn't format the data in json, you could format it yourself:

public static void Post(string RequestURL, string Post1, string Post2)
{
    using (var wb = new WebClient())
    {
        var data = string.Format("{0}\"{1}\":\"{2}\"{3}", "{", Post1, Post2, "}");
        var response = wb.UploadString(RequestURL, "POST", data);
    }
}

Or use a JSON serializer such as NewtonSoft

answered Aug 30, 2018 by digger
• 26,550 points

Related Questions In Blockchain

0 votes
1 answer

How to make my Dapp work on regular browsers?

There are ethereum supporting browsers like Metamask, ...READ MORE

answered Jun 20, 2018 in Blockchain by ariaholic
• 7,340 points
44 views
0 votes
1 answer

How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

answered Mar 26, 2018 in Blockchain by Christine
• 15,790 points

edited Mar 26, 2018 by Christine 125 views
+1 vote
1 answer

How to deploy ethereum smart contracts on a website?

There are many ways to do this: 1 ...READ MORE

answered Mar 26, 2018 in Blockchain by Johnathon
• 9,080 points
101 views
0 votes
1 answer

How to create a new wallet on a blockchain?

Firstly, you need to have a clear ...READ MORE

answered Apr 4, 2018 in Blockchain by Christine
• 15,790 points
90 views
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,340 points
92 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
172 views
0 votes
1 answer
0 votes
1 answer

How to return data on execution of invoke function?

You can do this using a response ...READ MORE

answered Jul 23, 2018 in Blockchain by digger
• 26,550 points
40 views
0 votes
1 answer

Google API post request to IBM blockchain error

You have specified query as parameter to method and function but if you ...READ MORE

answered Sep 14, 2018 in Blockchain by digger
• 26,550 points
29 views