简体   繁体   English

如何使用c#将数据发布到url

[英]how to post data to url using c#

i want send this data using post method in c# 我想在C#中使用post方法发送此数据

POST https://lyncweb.contoso.com/ucwa/oauth/v1/applications/103...740/onlineMeetings/    myOnlineMeetings HTTP/1.1
 Accept: application/json
 Content-Type: application/json
 Authorization: Bearer cwt=AAEB...buHc
 X-Ms-Origin: http://localhost
 X-Requested-With: XMLHttpRequest
 Referer: https://lyncweb.contoso.com/Autodiscover/XFrame/XFrame.html
 Accept-Language: en-US
 Accept-Encoding: gzip, deflate
 User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Trident/6.0;.NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; InfoPath.3)
 Host: lyncweb.contoso.com
 Content-Length: 185
 DNT: 1
 Connection: Keep-Alive
 Cache-Control: no-cache

 {
 "attendanceAnnouncementsStatus":"Disabled",
 "description":"hey guys let's do a musical!",
 "subject":"holiday party",
 "attendees": ["sip:Chris@contoso.com","sip:Alex@contoso.com"],
 "leaders": []
 }

please help me to write code in c# desktop application. 请帮助我在C#桌面应用程序中编写代码。

You can use Restsharp it is an lib that you can get from Nuget . 您可以使用Restsharp它是一个可以从Nuget获得的Nuget very easy to use: 非常容易使用:

here is an example: 这是一个例子:

var client = new RestClient("http://example.com");
// client.Authenticator = new HttpBasicAuthenticator(username, password);

var request = new RestRequest("resource/{id}", Method.POST);
request.AddParameter("name", "value"); // adds to POST or URL querystring based on Method
request.AddUrlSegment("id", "123"); // replaces matching token in request.Resource

// easily add HTTP Headers
request.AddHeader("header", "value");

// add files to upload (works with compatible verbs)
request.AddFile(path);

// execute the request
IRestResponse response = client.Execute(request);
var content = response.Content; // raw content as string

// or automatically deserialize result
// return content type is sniffed but can be explicitly set via RestClient.AddHandler();
RestResponse<Person> response2 = client.Execute<Person>(request);
var name = response2.Data.Name;

// easy async support
client.ExecuteAsync(request, response => {
    Console.WriteLine(response.Content);
});

// async with deserialization
var asyncHandle = client.ExecuteAsync<Person>(request, response => {
    Console.WriteLine(response.Data.Name);
});

// abort the request on demand
asyncHandle.Abort();

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

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