c# - 调用 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 类来发送请求,但它失败了。任何建议如何处理?
解决方案
推荐阅读
- event-handling - 在 ejs 模板上触发事件?
- android - 如何取消协程中的阻塞代码
- arrays - 在汇编中声明和索引 qwords 的整数数组
- acumatica - 如何抑制客户类更新
- python - 列重命名:在数字和字母之间切换
- javascript - 如何更改 webpack 构建中的所有 href 和 src 路径?
- scala - Scala spark,输入数据框,返回所有值等于 1 的列
- jenkins - Jenkins - 使用来自不同 groovy 文件中的列表变量的选项填充选择参数
- visual-studio-2019 - Visual Studio 2019 (v16.3.5) - 更新 EDMX 文件更改所有模型上的间距和缩进
- reactjs - 如何设置类似于 Material-UI 的轮廓文本字段的静态轮廓 div?