问题:webclient请求的时候,远程服务器返回400错误,
但是数据又传送给对方了,很困惑为啥会catch到400错误。
代码在:
byte[] byRemoteInfo = webClientObj.UploadValues(strUrl,postVars);
这里报的异常,返回
{"远程服务器返回错误: (400) 错误的请求。"}
//注释里的更改请求头的几个方法都试过了,不好使。
private void SendPost(int agent, string secretKey, string strUrl, ViewModels.GetReInfoViewModel viewModel, string cameraName)
{
agent = 1;//代理人id
secretKey = "miyao";
strUrl="请求串";//第三方接收的url,demo:http://www.baidu.com/webapi/postvalues?access_token=passsecrete
try
{
var webClientObj = new WebClient();
var postVars = new System.Collections.Specialized.NameValueCollection();
//返回状态内容
postVars.Add("BusinessStatus", viewModel.BusinessStatus.ToString());
postVars.Add("StatusMessage", viewModel.StatusMessage);
//webClientObj.Encoding = Encoding.UTF8;
byte[] byRemoteInfo = webC**lientObj.UploadValues(strUrl,postVars);
//返回值
string remoteInfo = Encoding.UTF8.GetString(byRemoteInfo);
logInfo.Info(string.Format("请求第三方{0}接口返回消息:{1}", agent, remoteInfo));
}
catch (Exception ex)
{
logError.Error("调用" + agent + "接口传摄像头续保信息接口异常,Url为:" + strUrl + ";\n 异常信息:" + ex.StackTrace + " \n " + ex.Message);
}
}