简体   繁体   English

从asp.net core 2.0 HttpClient发布json以卷曲,并附带其他信息

[英]posting json to curl from asp.net core 2.0 HttpClient with additional information

I am trying to call below url from my code using asp.net core 2.0 web api: 我正在尝试使用asp.net Core 2.0 Web API从我的代码中调用以下URL:

curl -H "Content-Type: text/plain" --data '{"key":"[your-key-here]","addr":"183qrMGHzMstARRh2rVoRepAd919sGgMHb","callback":" https://mystore.com?invoice_id=123 ","onNotification":"KEEP", "op":"RECEIVE", "confs": 5}' https://api.blockchain.info/v2/receive/balance_update curl -H“内容类型:文本/纯文本” --data'{“ key”:“ [此处为您的键]”,“ addr”:“ 183qrMGHzMstARRh2rVoRepAd919sGgMHb”,“回调”:“ https:// mystore。 com?invoice_id = 123 “,” onNotification“:” KEEP“,” op“:” RECEIVE“,” confs“:5}' https://api.blockchain.info/v2/receive/balance_update

I created a Model to post with cURL like this: 我创建了一个使用cURL发布的模型,如下所示:

public class ReceiveModel
    {
        public string key { get; set; }
        public int id { get; set; }
        public string addr { get; set; }
        public string op { get; set; }
        public int confs { get; set; }
        public string callback { get; set; }
        public string onNotification { get; set; }
    }

and calling it like this: 并这样称呼它:

public const string baseurl = "https://api.blockchain.info/v2/receive/balance_update";
public async Task<object>ReceiveBitcoins(ReceiveModel recd)
        {
            recd.key = "xxxxxxxx";

            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(rooturl);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain"));

            var response = await client.PostAsync(rooturl, recd);
   return response;
        }

Please note recd is the ReceivedModel whose other fields are coming from WepApi post and api key is getting entered here only. 请注意,recd是ReceivedModel,其其他字段来自WepApi帖子,并且仅在此处输入api密钥。

Is this the correct implementation? 这是正确的实现吗? Do I need to take care of -H and --data, if so, how may I achieve this. 我是否需要照顾-H和--data,如果可以的话,如何实现?

The response I get from this is : 我从中得到的答复是:

    {"result":{"version":{"major":1,"minor":1,"build":-1,"revision":-1,"majorRevision":-1,"minorRevision":-1},"content":{"headers":[{"key":"Content-Length","value":["109"]},{"key":"Content-Type",
"value":["application/json"]}]},"statusCode":400,"reasonPhrase":"Bad Request","headers":[{"key":"Connection","value":["keep-alive"]},{"key":"Date",
"value":["Fri, 26 Jan 2018 11:31:19 GMT"]},{"key":"Via","value":["1.1 google"]},{"key":"Server","value":["cloudflare"]},{"key":"Set-Cookie","value":["__cfduid=dedf2c6d34e69eeeeeeeeec9b7f1516966278; expires=Sat, 26-Jan-19 11:31:18 GMT; 
path=/; domain=.blockchain.info; HttpOnly"]},{"key":"X-Blockchain-CP-F","value":["2fgz 0.010"]},{"key":"X-Blockchain-Server","value":["BlockchainFE/1.0"]},
{"key":"Strict-Transport-Security","value":["max-age=31536000; includeSubDomains; preload"]},{"key":"X-Content-Type-Options","value":["nosniff"]},{"key":"X-XSS-Protection","value":["1; mode=block"]},{"key":"Alt-Svc","value":["clear"]},
{"key":"Expect-CT","value":["max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""]},{"key":"CF-RAY","value":["3e33252b3fdd8a55-BOM"]}],"requestMessage":{"version":{"major":1,"minor":1,"build":-1,
"revision":-1,"majorRevision":-1,"minorRevision":-1},"content":{"headers":[{"key":"Content-Type","value":["application/json"]},{"key":"Content-Length",
    "value":["222"]}]},"method":{"method":"POST"},"requestUri":
    "https://api.blockchain.info/v2/receive/balance_update","headers":[{"key":"Accept","value":["text/plain"]},
    {"key":"x-ms-request-root-id","value":["1e0xxxxx669-46xxx11d79afac17e"]},{"key":"x-ms-request-id","value":["|1e0xxx69-462511xxxxac17e.1."]},{"key":"Request-Id","value":["|1e0axxx9-462xxxx1xxxxe.1.1."]}],"properties":{}},"isSuccessStatusCode":false},"id":4,"exception":null,"status":5,"isCanceled":false,"isCompleted":true,"isCompletedSuccessfully":true,"creationOptions":0,"asyncState":null,"isFaulted":false}

This is 这是

Please help. 请帮忙。

When you fill out this request through CURL, does it work? 当您通过CURL填写此请求时,它有效吗? Is your "ReceiveBitcoins" method invoked? 是否调用了“ ReceiveBitcoins”方法?

curl -H "Content-Type: text/plain" --data '{"addr":"183qrMGHzMstARRh2rVoRepAd919sGgMHb","callback":" https://mystore.com?invoice_id=123 ","onNotification":"KEEP", "op":"RECEIVE", "confs": 5}' curl -H“内容类型:文本/纯文本” --data'{“ addr”:“ 183qrMGHzMstARRh2rVoRepAd919sGgMHb”,“回调”:“ https://mystore.com?invoice_id=123 ”,“ onNotification”:“ KEEP” ,“ op”:“ RECEIVE”,“ confs”:5}'

Yes, in fact, it will return the result for any callback URL that you enter ... Do you have the documentation for this endpoint " https://api.blockchain.info/v2/receive/balance_update "? 是的,实际上,它将为您输入的任何回调URL返回结果。...您是否有此终结点的文档“ https://api.blockchain.info/v2/receive/balance_update ”? In the documentation of this API, it tells you how it sends the data to your url callback. 在此API的文档中,它告诉您如何将数据发送到url回调。

Yes, in fact, it will return the result to any callback URL that you enter. 是的,实际上,它将结果返回到您输入的任何回调URL。

In order for you to receive this information, you must create a new method to receive this response, for example: 为了使您收到此信息,必须创建一个新方法来接收此响应,例如:

//This method is invoked via the url "https://mystore.com/balance-update".
public async Task<object>BalanceUpdate()
{
     // Perform the data processing here. According to the API documentation.
}

And in your callback, you specify the url to access this method " https://mystore.com/balance-update ", meaning your callback would look like this "callback = https: //mystore.com/balance-update" . 在您的回调中,您可以指定URL来访问此方法“ https://mystore.com/balance-update ”,这意味着您的回调应类似于“ callback = https://mystore.com/balance-update”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM