【发布时间】:2017-07-30 16:20:07
【问题描述】:
我正在尝试使用 RestSharp 发布以下 JSON:
{ "username": "test_user", "password": "super$3kretp4ssword" }
这是我写的c#代码
var client = new RestClient("https://accept.paymobsolutions.com/api/auth/tokens");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", request.AddJsonBody(new { username = "myUsername", password = "myPassword" }), ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
但在调试时response.content 是""
响应应该是:
{
"token": "ZXlKaGlPaUpJVXpVeE1pSX1Y0NJmV5Sn...", // this is your authentication token
"profile": {
"id": 28, // this is your merchant_id
"user": {
"id": 31,
"username": "test_user",
"first_name": "test_user",
"last_name": "test_user",
},
"created_at": "2016-11-20T16:27:20.067296Z",
...
}
}
【问题讨论】:
-
response变量的其他字段是什么? -
@Progman 请查看编辑
-
不,您的
response变量的其他字段是什么?特别是StatusCode字段。 -
response.StatusCode = 0
-
response变量中的所有字段是什么?请编辑问题以包含所有字段以及它们从response变量中获得的值。它们可能包含请求失败的原因信息。在您的情况下,它看起来甚至没有发送到服务器。