csharp-leaf / Leaf.xNet

HTTP Library. Impoved original xNet.
https://github.com/csharp-leaf
180 stars 52 forks source link

Send request #93

Closed HideakiAtsuyo closed 4 years ago

HideakiAtsuyo commented 4 years ago

How to send body in Patch request

grandsilence commented 4 years ago
var jsonContent = new StringContent("{\"json\": true}") {
    ContentType = "application/json"
};

// content is optional and also can be as form or multipart form
var resp = HttpRequest.Raw(HttpMethod.PATCH, new Uri("https://google.com/test", jsonContent);
string respStr = resp.ToString();
HideakiAtsuyo commented 4 years ago

impossible conversion from 'Leaf.xNet.StringContent' to 'bool'. for the jsonContent in new Uri

abhay991 commented 4 years ago

He forgot to put bracket but i think it's easy to find out what parameters Raw method takes.

var jsonContent = new StringContent("{\"json\": true}")
{
    ContentType = "application/json"
};

// content is optional and also can be as form or multipart form
var resp = req.Raw(HttpMethod.PATCH, "https://google.com/test", jsonContent);
string respStr = resp.ToString();
HideakiAtsuyo commented 4 years ago

Working but how can i find the status code response with leaf xnet?? I don't can see him only for Exception

abhay991 commented 4 years ago

Raw method or any of Get/Post/Put method returns HttpResponse which does have status code and all required stuff you would need. Here we have assigned 'resp' variable for response so check that to get status code.

HideakiAtsuyo commented 4 years ago

Yeah i have it with request.Response.StatusCode thanks solved