简体   繁体   English

卷曲发布 Xamarin c#

[英]curl post Xamarin c#

How do I do something simple as :我如何做一些简单的事情:

curl -X POST --data-binary '{"a":"b"}' --location "$URL"

I am working on Xamarin, c#我正在研究 Xamarin,c#

I am having problems with the dependecies.我有依赖关系的问题。

You could use HttpClient by adding a system reference to System.Net.Http .您可以通过添加对System.Net.Http的系统引用来使用HttpClient Use the following sample code to create a client and submit the same call.使用以下示例代码创建客户端并提交相同的调用。 Note that you could use another framework for converting class types into JSON text like Json.NET.请注意,您可以使用另一个框架将类类型转换为 JSON 文本,例如 Json.NET。 Note that the following example shows how to construct HttpClient , but you should not dispose of the instance and track it elsewhere .请注意,以下示例显示了如何构造HttpClient ,但您不应处置该实例并在其他地方对其进行跟踪

var client = new HttpClient()

string content = "{\"a\":\"b\"}";
StringContent httpContent = new StringContent(content);

var response = await client.PostAsync("$URL", httpContent);

if (response.IsSuccessStatusCode)
{
    var responseContent = await response.Content.ReadAsStringAsync();
    // Show response. 
}
else
{
    // Show error.
}

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

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