我创建了一个PostMan请求。 JSON的基本“发布”。在Postman中工作正常! 当我在PostMan中单击“ 代码”并为 C#RestSharp 选择生成代码段时,它将生成以下内容:
var client = new RestClient("https://localhost:44331/api/workorder");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", " { \"dataSource\":\"Axw163\",\"Number\":\"3450489\",\"UserId\":\"XXX\",\"Password\":\"XXX\",\"EndPoint\":\"http://MYENDPOINT\",\"App\": \"WORK\"}\r\nstrong text", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
当我将代码粘贴到我的应用中并运行它时,我得到以下信息:
{ "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1", "title": "One or more validation errors occurred.", "status": 400, "traceId": "|49b7f241-4e7e8b1ee8900c92.", "errors": { "$": ["The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0."] } }
您知道为什么它可以在Postman中工作而不在生成的C#代码中工作吗?
这里是邮递员
"id": "a59638d6-4f81-4318-bc55-181a088c00a4",
"name": "https://localhost:44331/api/workorder",
"url": "https://localhost:44331/api/workorder",
"description": "Get Work Order",
"data": [],
"dataOptions": {
"raw": {
"language": "json"
}
},
"dataMode": "raw",
"headerData": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"description": "",
"type": "text"
}
],
"method": "GET",
"pathVariableData": [],
"queryParams": [],
"auth": null,
"events": null,
"folder": null,
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"currentHelper": null,
"helperAttributes": null,
"collectionId": "64bf01de-822f-41d3-b596-7c351a8665e8",
"rawModeData": " { \"dataSource\":\"XXX\",\"Number\":\"3450489\",\"UserId\":\"XXX\",\"Password\":\"XX\",\"EndPoint\":\"http://xxxxxxxxxcloudapp.azure.com/AppXtenderrest\",\"App\": \"WMIS_WORK_REQUEST\"}\r\n ",
"headers": "Content-Type: application/json\n",
"pathVariables": {}