获取有效请求正文的BadRequest响应

时间:2018-03-12 04:28:40

标签: c# json rest

我试图将一些JSON发布到Service Now API(Service Desk软件),这是一个非常烦人的问题。

从PowerShell发送时效果很好,但在C#中我只是

  

" StatusCode:BadRequest,Content-Type:application / json; charset = UTF-8,Content-Length:-1)"

留言

  

" {\"错误\":{\" detail \":\" Cannod decode:java.io.StringReader@399624 \& #34;,\"消息\":\"读取请求时出现异常\"},\"状态\":\"失败\"}"

除了C#需要""{{}}转义字符这一事实外,请求JSON 完全相同。

调试时,我粘贴了保存的正文字符串并对json验证器进行了验证。

我该怎么调试呢?非常感谢任何帮助。

C#

var client = new RestClient("https://instance.service-now.com");

var request = new RestRequest("api/now/v1/table/incident", Method.POST);
client.Authenticator = new HttpBasicAuthenticator("bassie.surname", pw());
request.RequestFormat = DataFormat.Json;
request.AddJsonBody(body);
request.UseDefaultCredentials = true;

var response = client.Execute(request);

,其中

    var body = $@"
{{
    ""parent"":  """",
    ""u_attachment_records"":  """",
    ""u_bsc_service_type"":  """",
    ""caused_by"":  """",
    ""watch_list"":  """",
    ""upon_reject"":  ""cancel"",
    ""sys_updated_on"":  ""{now}"",
    ""approval_history"":  """",
    ""u_is_parent"":  ""false"",
    ""skills"":  """",
    ""u_classification"":  ""{ticket.Classification}"",
    ""u_affected_contact"":  ""{ticket.AffectedContact}"",
    ""state"":  ""{inProgressState}"",
    ""u_last_time_stamp"":  """",
    ""u_major_incident_manager"":  """",
    ""u_next_step"":  """",
    ""sys_created_by"":  ""{ticket.AssignedTo}"",
    ""u_category_grouping"":  ""IT"",
    ""knowledge"":  ""false"",
    ""order"":  """",
    ""u_attachment_logs"":  """",
    ""u_attachments"":  """",
    ""cmdb_ci"":  """",
    ""delivery_plan"":  """",
    ""u_previous_assignment_groups"":  """",
    ""impact"":  ""{lowUrgency}"",
    ""active"":  ""true"",
    ""priority"":  ""{lowPriority}"",
    ""u_previous_number"":  """",
    ""group_list"":  """",
    ""u_bt_correlation_id"":  """",
    ""approval_set"":  """",
    ""u_bsc_accounting_period"":  """",
    ""u_r3"":  ""false"",
    ""short_description"":  ""{ticket.Description}"",
    ""correlation_display"":  """",
    ""delivery_task"":  """",
    ""work_start"":  """",
    ""u_third_party"":  """",
    ""u_requestor_rejection_count"":  ""0"",
    ""additional_assignee_list"":  """",
    ""u_requestor"":  ""{ticket.AffectedContact}"",
    ""notify"":  ""1"",
    ""sys_class_name"":  ""{ticket.Classification}"",
    ""u_sla_breach_code"":  """",
    ""closed_by"":  """",
    ""follow_up"":  """",
    ""u_contact_details"":  """",
    ""reassignment_count"":  ""0"",
    ""assigned_to"":  ""{ticket.AssignedTo}"",
    ""sla_due"":  """",
    ""u_workstation_location"":  """",
    ""u_resolver_watch_list"":  """",
    ""u_created_from"":  """",
    ""u_my_work_priority"":  """",
    ""escalation"":  ""0"",
    ""upon_approval"":  ""proceed"",
    ""u_effort"":  """",
    ""u_incident_model"":  """",
    ""correlation_id"":  """",
    ""u_approver_list"":  """",
    ""u_previous_step"":  """",
    ""u_gbs_id"":  """",
    ""u_inc_sub_status"":  """",
    ""u_customer_acceptance"":  """",
    ""made_sla"":  ""true"",
    ""u_stakeholder_group_list"":  """",
    ""u_major_incident"":  ""false"",
    ""u_bsc_service_group"":  """",
    ""u_request_id"":  """",
    ""u_building"":  """",
    ""u_stakeholder_watch_list"":  """",
    ""sys_updated_by"":  ""system"",
    ""opened_by"":  ""{ticket.CreatedBy}"",
    ""u_bsc_legal_entity"":  """",
    ""u_bsc_operating_unit"":  """",
    ""user_input"":  """",
    ""sys_created_on"":  ""{now}"",
    ""sys_domain"":  {{
                       ""link"":  ""https://instance.service-now.com/api/now/table/sys_user_group/global"",
                       ""value"":  ""global""
                   }},
    ""u_adms_assignedto_count"":  ""0"",
    ""u_escalate_ticket"":  ""false"",
    ""u_bsc_quality_check_result"":  """",
    ""calendar_stc"":  ""505043"",
    ""u_total_effort"":  """",
    ""u_escalate_ticket_date"":  """",
    ""u_resolution_reason"":  """",
    ""u_internal_ref"":  """",
    ""u_enhancement_defect_id"":  """",
    ""business_service"":  """",
    ""u_adms_assigned"":  """",
    ""u_hcl_correlation_id"":  """",
    ""u_symptom"":  ""general_failure"",
    ""rfc"":  """",
    ""time_worked"":  """",
    ""u_quick_closed"":  ""false"",
    ""expected_start"":  """",
    ""opened_at"":  ""{now}"",
    ""u_ebond_lock"":  ""false"",
    ""work_end"":  """",
    ""caller_id"":  """",
    ""u_dsyg_project_name"":  """",
    ""u_resolver_group_list"":  """",
    ""subcategory"":  """",
    ""work_notes"":  """",
    ""assignment_group"":  {{
                             ""link"":  ""https://instance.service-now.com/api/now/table/sys_user_group/a5c69cd2c55f01c427c9c96cacebf391"",
                             ""value"":  ""a5c69cd2c55f01c427c9c96cacebf391""
                         }},
    ""business_stc"":  ""126137"",
    ""u_dsyg_project_number"":  """",
    ""calendar_duration"":  ""1970-01-06 20:17:23"",
    ""u_external_ref"":  """",
    ""close_notes"":  """",
    ""contact_type"":  ""phone"",
    ""u_acceptance_method"":  ""Automatic"",
    ""u_third_party_reference"":  """",
    ""incident_state"":  ""1"",
    ""urgency"":  ""{lowUrgency}"",
    ""problem_id"":  """",
    ""u_adms_first_assignto"":  ""false"",
    ""company"":  """",
    ""activity_due"":  """",
    ""severity"":  ""3"",
    ""u_last_attached_kb"":  """",
    ""comments"":  """",
    ""approval"":  ""not requested"",
    ""due_date"":  """",
    ""sys_mod_count"":  ""1"",
    ""sys_tags"":  """",
    ""u_resolution_code"":  ""resolved_unknown"",
    ""u_resolution_activities"":  """",
    ""u_service_zone"":  {{
                           ""link"":  ""https://instance.service-now.com/api/now/table/u_service_zone/8f2b4c9a382de00097ba6b481956396b"",
                           ""value"":  ""8f2b4c9a382de00097ba6b481956396b""
                       }},
    ""u_stakeholder_communications"":  """",
    ""location"":  {{
                     ""link"":  ""https://instance.service-now.com/api/now/table/cmn_location/eafd7038517de000c86dc462c016ea6b"",
                     ""value"":  ""eafd7038517de000c86dc462c016ea6b""
                 }},
    ""category"":  """",
    ""u_bsc_service_category"":  """"
}}
";

0 个答案:

没有答案