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,310 points
974 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,720 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 aryya
• 7,440 points
217 views
0 votes
1 answer

How to trigger change blockchain network request on MetaMask

was finally able to find the answer: await ...READ MORE

answered Mar 31 in Blockchain by Rahul
• 8,980 points
23 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 889 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 27, 2018 in Blockchain by Johnathon
• 9,090 points
1,141 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 aryya
• 7,440 points
595 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
913 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,720 points
212 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,720 points
186 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP