首页 > 解决方案 > 调用 ashx 服务返回 500 内部服务器错误,即使服务完成业务

问题描述

我正在调用 ashx 服务以在第三方上创建用户,我设置了 URL 和查询字符串参数。请求接受 POST/GET http 方法,响应应返回响应代码和响应文本为 xml。

奇怪的是正在创建用户,但响应引发异常 [500 内部服务器错误]。

这是代码:

string URI = "https://thirdpartyservice.com/ApiHandler.ashx?";
string params = "ptf_cmd=403&ptf_method=md5" +
            "&ptf_timer=" + sTimer +
            "&ptf_check=" + sCheck +
            "&ptf_client=" + rsaClient +
            "&ptf_partner=" + sPartner +
            "&ptf_offername=" + offername +
            "&ptf_host=" + rsaHost +
            "&ptf_login=" + sLogin +
            "&ptf_password=" + password +
            "&ptf_firstname=" + firstName +
            "&ptf_lastname=" + lastName +
            "&ptf_email=" + userEmail +
            "&ptf_interfacelanguage=" + rsaInterfaceLanguage +
            "&ptf_role=" + rsaUserRole +
            "&ptf_pupildiscipline=" + rsaPupilDiscipline +
            "&ptf_detailedResult=1" +
            "&ptf_endingurl=" + rsaReturnUrl +
            "&ptf_admingroup=" + rsaAdminGroup +
            "&ptf_pedagroup=" + rsaPedaGroup +
            "&ptf_usercreationmode=API";
            using (var wc = new WebClient())
            {
                wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";  
                string xmlResult = wc.DownloadString(URI + params); //throws exception [500 Internal Server Error].
                //string xmlResult = wc.UploadString(URI, params);//throws exception [500 Internal Server Error].
            }

我在没有设置标头和 POST/GET 的情况下尝试了请求,但也引发了异常。我也使用 HttpWebRequest 类来发送请求,但它失败了。任何建议如何处理?

标签: c#web-servicesashx

解决方案


推荐阅读