![](/img/trans.png)
[英]Grapevine.RESTClient throws exception about cookies if service is not up
[英]Grapevine RestClient Json Body
我很難通過發送json內容來組合請求,在4.x文檔中找不到任何與版本3.x完全不同的內容
RestClient client = new RestClient();
client.Host = "localhost";
client.Port = 8080;
RestRequest request = new Grapevine.Client.RestRequest("/route1");
request.HttpMethod = HttpMethod.POST;
RestResponse response = client.Execute(request) as RestResponse;
代碼中的某處 - 在發送請求之前 - 您需要設置請求的正文(或有效負載)。
request.Payload = "send this data";
有效負載只是一個字符串,因此您可以在進行分配之前將對象序列化為JSON字符串(並適當設置ContentType
屬性)。 Json.NET庫被廣泛用於實現此目的。 您也可以手動執行此操作:
request.ContentType = ContentType.JSON;
request.Payload = "{\"key\":\"value\"}";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.