【发布时间】:2021-03-10 23:20:47
【问题描述】:
我正在尝试使用 C# 构建一个肥皂信封;我收到错误消息:“指定的值包含无效的 HTTP 标头字符。参数名称:名称”添加标头时。 当我使用即时窗口检查 BuildSoapHeader() 的输出时,我仍然看到转义序列“\”文字,我想知道这是问题所在还是其他原因。
请帮忙!
WebRequest webRequest = WebRequest.Create(this._fiserveURI);
HttpWebRequest httpRequest = (HttpWebRequest)webRequest;
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml; charset=utf-8";
httpRequest.Headers.Add(this.BuildSoapHeader());
...
private string BuildSoapHeader()
{
StringBuilder retValue = new StringBuilder("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" ");
retValue.Append("xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" ");
retValue.Append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
retValue.Append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> ");
retValue.Append("<SOAP-ENV:Header>");
retValue.Append("<m:PI00WEBSOperationRequest_header xmlns:m=\"http://www.FiservLSP.RequestHeader.com\">");
retValue.Append("<m:LSPHeader>");
retValue.Append("<m:Service>");
retValue.Append("<m:DateTime>" + DateTime.Now.ToString() + "</m:DateTime>");
retValue.Append("<m:uuid>" + this._fiserveUUID +"</m:uuid>");
retValue.Append("</m:Service>");
retValue.Append("<m:Security>");
retValue.Append("<m:AuthenticationMaterial>");
retValue.Append("<m:PrincipalPWD>" + this._fiservePrincipalPWD + "</m:PrincipalPWD>");
retValue.Append("<m:PrincipalID>"+ this._fiservePrincipalID +"</m:PrincipalID>");
retValue.Append("</m:AuthenticationMaterial>");
retValue.Append("</m:Security>");
retValue.Append("<m:Client>");
retValue.Append("<m:VendorID>" + this._fiserveVendorID + "</m:VendorID>");
retValue.Append("<m:AppID>" + this._fiserveAppID + "</m:AppID>");
retValue.Append("<m:OrgID>" + this._fiserveOrgID + "</m:OrgID>");
retValue.Append("<m:SessionID>" + this._fiserveSessionID + "</m:SessionID>");
retValue.Append("</m:Client>");
retValue.Append("<m:DataSource>");
retValue.Append("<m:URI>" + this._fiserveURI + "</m:URI>");
retValue.Append("</m:DataSource>");
retValue.Append("</m:LSPHeader>");
retValue.Append("</m:PI00WEBSOperationRequest_header>");
retValue.Append("</SOAP-ENV:Header>");
//retValue.Append("<SOAP-ENV:Body></SOAP-ENV:Body>");
retValue.Append("</SOAP-ENV:Envelope>");
return retValue.ToString();
}
【问题讨论】: